Eclipse Java project: best way to include external JAR if the project is shared?

Oct 27, 2007
17,009
5
0
For my senior project I'm developing an Eclipse plugin. We are using Eclipse to develop it and subversion for the repository. I want to include JUnit for testing. What's the best way of including a JAR library in the project in this situation? I'm thinking I just copy the JUnit .jar into the project and include it in the build path. Will this ensure it works on everyone's computer, even if they don't have JUnit in an existing CLASSPATH?

This CLASSPATH stuff seems to get an order of magnitude trickier with shared projects, sorry about the dumb question. Thanks in advance.
 

Tea Bag

Golden Member
Sep 11, 2004
1,575
3
0
It depends on your build strategy but you shouldn't have to modify CLASSPATH env variable in any of these methods.

If everyone has Eclipse and they check out your project Eclipse should handle it for you - if everyone's on the same version of Eclipse just copy the JUnit JAR in your project and check the whole project in (excluding compiled code). The Eclipse project properties should take care of that for you when it's imported into the Workspace.

If it's going to be built / tested external of the IDE like on command line, build / CI server etc.. you have a couple options.

One is use ANT to create a build file and put a test task in there to run your unit tests. Eclipse has great ANT support built in.

Optionally - extending on ANT for build management, you can use Maven2 and as long as you have internet access you can set up your project to build with a config file that builds, tests, compiles and packages by default. It will download the required JARs from a public repository and cache them for future use locally. The only prerequisite is your project adheres to Mavens project layout. The nice thing about this method is there is never 3rd party JARS checked into source for the purpose of building. There is a Maven2 Plugin for Eclipse that makes life a bit easier as well.

These are listed in terms of quickest to longest time-wise to implement. my suggestion would be ANT or M2 with M2 having a bit more of a learning curve right away. If you don't have the time, I'd do the ANT build script.
 
Oct 27, 2007
17,009
5
0
Thanks for the info, that helps a lot. I don't think I'll go the Maven route because it's likely that people will work on the project some time during the year without internet access (on trains, overseas vacations, etc). I was just a bit paranoid because one team member recently checked in code with a dependency on a JAR that existed only her her own computer (D:) which was annoying to say the least. Just wanted to make sure I wouldn't repeat her mistakes.

I'll look into ANT for sure. Thanks again.
 
Sep 29, 2004
18,656
67
91
Tea Bag gave some good advice.

At work, we put all our jars into a jar folder within the project. Then add them to the project via project settings.

Everyone then gets everything proerly configured upon checkout.