Relative class paths in eclipse

In eclipse you can only reference jars via a path into the workspace, you can use relative paths (if you edit the .classpath outside of eclipse) but this relative path cannot expand outside of the workspace. This is a problem if you are using svn:externals to add an externals directory into a repository that contains many repositories ie:


If Foo and Bar are eclipse projects then referencing jars in Externals will find the jars relative to root. This is obviously fragile. There is no complete fix to this, what you can do is use a variable: (you will need to adjust the menus for windows I am using osx)

Navigate to Java/BuildPath/Classpath Variables
Add a new variable (LOCAL_INSTALLED_JARS) and point this to the Externals sub dir

Now when you add jars (Configure Build Path) Press add variable, select the variable then click expand, this should popup a chooser in the Externals sub dir, select the jar and click ok. DONE:

This will add the following to the .classpath file:

<classpathentry kind="var" path="LOCAL_INSTALLED_JARS/log4j-1.2.11.jar"/

So if you work from a different root you only have to update the LOCAL_INSTALLED_JARS variable.. magic.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: