views:

1200

answers:

5

I'm trying to create a centralized folder (in some kind of a "meta project" in my eclipse workspace) for commonly used JAR files for referenced projects in this workspace. It should work similar to the WEB-INF/lib folder for web projects but also apply to non web projects, and automatically scan and add all jar files in this folder.

I tried to create a user library with these jar files and reference them in the project but I still have to add every new jar manually to the user library (and don't know if it is referenced relative of absoulute) and Tomcat (WTP) doesn't seem to take these files (Run As -> Run on Server) into its classpath (and I don't want to duplicate the jars and put them into WEB-INF/lib). Any ideas?

+2  A: 

I would recommend against this, it becomes a pain in the butt when you have lots of projects with overlapping dependencies.

What if Project X uses commons-logging-1.0 but someone creates Project Z which really needs commons-logging-1.1 instead? Do you want your central folder to have copies of the same JAR for each possible version number?

Use a build tool like Maven or Ivy which will download and handle dependent JARs for you. The maven-eclipse plugin does a pretty good job of generating .project/.classpath files for Eclipse which will automatically put all dependent JARs on the build path, and m2eclipse is also good at handling dependencies from within Eclipse.

matt b
A: 

I think you should take a serious look at Maven. You simply declare what 'artifacts' each of your projects depends on, and Maven will take care of fetching the JARs from a repository, adding them to the build classpath, and including them in your WAR files. And if you want to a batch build, you don't need to create an Ant "build.xml" file: just run "mvn" from the command file.

Stephen C
+1  A: 

I would consider managing these things with the Ivy extension to Ant, which has the benefit of being maven compatible should you ever want to go that way.

Just throwing everything in a big pile will give you problems eventually, as you will run into version problems when you suddenly have two projects where one uses the version available when THAT was created,a nd the other one the bugfixed version, and those are not 100% compatible.

Thorbjørn Ravn Andersen
+3  A: 

+1 for Ivy.

If you'd rather do it in a separated project in Eclipse:

You added the 'common project' as on dependency for other projects (Java Build Path->Projects, then Add). But, have you exported the jars of the 'common project'? (In the common project: Java Build Path->Order and Export, then check all jars).

fg
+1 Exporting the jars in the project settings works much better than user libraries, especially since you can put these settings under version control which is not possible with user libs.
Aaron Digulla
+1 It seems to me exporting the jars is the bit you are missing
Pablojim
Thanks, that looks way better than the user library and works. Still need to get Tomcat somehow running with these libraries but I hope that'll work. I will have a look at Maven and/or Ivy for sure though. Hopefully I can convince the other team members from using it.
Daff
A: 

My colleague implemented a classpath container which recursivly looks for jars in a given directory within the workspace, have a look at http://openscada.org/news/dx/31.05.2010154336JREJ4U.htm

The update site can be found at http://repo.openscada.org/p2/bob/R

The plugin is licensed unter LGPL V3 and you can find the source code under http://pubsvn.inavare.net/openscada/modules/bob/trunk/

Mauli