views:

1572

answers:

7

I'm having a difficult time figuring out how to add a .jar/library to a Netbeans project in such a way that I can get it committed to the repository.

The typical way to add a library (per the Netbeans documents I've already gone through) ends up with it just being local to me. Anyone who checks out my project ends up missing my required library.

Inserting it manually and trying to work around Netbeans results in Netbeans hanging while trying to scan the project...

So, how can I tell Netbeans to pick up a jar as a library and include it in my project in such a way that Subversion will be able to handle it?

+1  A: 

Not really an answer to your question but... generally you should not include these libraries in your subversion repository. There is usually no need to have them managed. What you might want is to set up a central repository similar to what happens with maven. If you use maven, you can create a local repository of libraries on a server accessible by the team. The dependencies on these libraries are entered in the pom.xml file and this is in the subversion repository. Now, as team members check out the code from subversion they all have access to the maven repository.

[I am looking for a reference to this right now. When I find it I'll edit this answer.]

Vincent Ramdhanie
+2  A: 

There are a couple ways to fix this.

A. When you define your Library, use a path to a common location. A location that's identical on everyone's machine--such as the location of a JAR installed with a third-party app into Program Files or /usr/local/ works well or a network drive.

Then, when they check-out the code, the path will still be correct and they do not have to define the Library on their Netbeans workspace.

B. Edit your project.properties file to use a relative path. Open your project.properties file and look for "libs.LIBRARY_NAME.classpath=...". That will be the "default" location used if the Library is not defined.

Change this to use a path relative to your project and store the jar files in your project. For example: libs.Log4J.classpath=lib/log4j.jar

Keep in mind that the Library definition in your Library Manager will override this value--so make sure you keep them in-sync (i.e. append a version number to the library name!).

C. Use Vincent's suggestion of using a build-system such as Maven. The Maven build-process will take care of downloading dependencies, etc. Netbeans has plugins for several popular build systems.

James Schek
Just changed manually the nbproject/project.properties and it works perfectly.
Gastoni
A: 

I ended up just downloading my own set and putting them on my local drive for this project. I setup my Netbeans to look there and warned the other guys what I did... Eventually, we'll have to do something a bit more scalable though... :-)

Brian Knoblauch
Yeah, I don't understand how this is acceptable. I want someone to be able to grab my project out of subversion with all of the attached libraries ready to compile and go.
rik.the.vik
I agree. Just doesn't seem to be possible though. Astounding that we could be having this problem in this day and age though. I figured all the stupid problems like this would have been solved long ago...
Brian Knoblauch
This entry now superceded by another answer by me.
Brian Knoblauch
+2  A: 

There is a new feature in NetBeans 6.5 (variable-based paths in projects) which should make this easier.

See http://wiki.netbeans.org/NewAndNoteWorthyNB65#section-NewAndNoteWorthyNB65-VariableBasedPathsInJ2SEJ2EEProjects for details. Note the screenshot includes variable references in the library customizer.

Tor Norbye
Very helpful, many thanks for this link!
mjustin
A: 

OK, the working solution that I've now moved to is to extract the class files out of the jars and dump them into the Source Packages area. Then it all gets committed to the repository and also avoids having to deal with handling a separate "lib" directory in the deployment phase.

This solution does everything I'm looking for, yet I feel real dirty about doing it this way. It just seems horribly broken and wrong... :-)

Brian Knoblauch
+1  A: 
j1c1m1b1