Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to instruct Eclipse to record relative paths of the external jars?

Tags:

eclipse

Here is my .classpath file, after I have added two more external jars (org.restlet.ext.simple.jar and org.simpleframework.jar):

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="src"/>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
    <classpathentry kind="lib" path="../3rd_party/restlet-jse-2.0.10/lib/org.restlet.ext.jackson.jar" sourcepath="C:/Program Files/Java/restlet-jse-2.0.10/src">
        <attributes>
            <attribute name="javadoc_location" value="file:/C:/Program Files/Java/restlet-jse-2.0.10/docs/ext/"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="lib" path="../3rd_party/restlet-jse-2.0.10/lib/org.restlet.ext.ssl.jar" sourcepath="C:/Program Files/Java/restlet-jse-2.0.10/src">
        <attributes>
            <attribute name="javadoc_location" value="file:/C:/Program Files/Java/restlet-jse-2.0.10/docs/ext/"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="lib" path="../3rd_party/restlet-jse-2.0.10/lib/org.restlet.jar" sourcepath="C:/Program Files/Java/restlet-jse-2.0.10/src">
        <attributes>
            <attribute name="javadoc_location" value="file:/C:/Program Files/Java/restlet-jse-2.0.10/docs/api"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="lib" path="../3rd_party/restlet-jse-2.0.10/lib/org.jsslutils_1.0/org.jsslutils.jar"/>
    <classpathentry kind="lib" path="../3rd_party/restlet-jse-2.0.10/lib/org.codehaus.jackson_1.4/org.codehaus.jackson.core.jar"/>
    <classpathentry kind="lib" path="../3rd_party/restlet-jse-2.0.10/lib/org.codehaus.jackson_1.4/org.codehaus.jackson.mapper.jar"/>
    <classpathentry kind="lib" path="../3rd_party/guice-3.0/aopalliance.jar"/>
    <classpathentry kind="lib" path="../3rd_party/guice-3.0/guice-3.0.jar"/>
    <classpathentry kind="lib" path="../3rd_party/guice-3.0/javax.inject.jar"/>
    <classpathentry kind="lib" path="C:/dev/poc/3rd_party/restlet-jse-2.0.10/lib/org.restlet.ext.simple.jar" sourcepath="C:/Program Files/Java/restlet-jse-2.0.10/src">
        <attributes>
            <attribute name="javadoc_location" value="file:/C:/Program Files/Java/restlet-jse-2.0.10/docs/ext/"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="lib" path="C:/dev/poc/3rd_party/restlet-jse-2.0.10/lib/org.simpleframework_4.1/org.simpleframework.jar"/>
    <classpathentry kind="output" path="bin"/>
</classpath>

Notice that they have been added with absolute paths, unlike other entries which are with relative ones, but only because I manually edit this file each time new external jars are added.

My question is can I somehow tell Eclipse to use relative paths of newly added external jars?

Thanks.

like image 344
mark Avatar asked Nov 29 '11 21:11

mark


People also ask

Where do I put external JARs in Eclipse Module path or classpath?

You can add a jar file in Eclipse by: right-clicking on the Project → Build Path → Configure Build Path. Under Libraries tab, click Add Jars or Add External JARs and give the Jar. Simple as that.

How do I select multiple JAR files in Eclipse?

Hold the shift key down while clicking on additional jars to add within the folder. This will allow you to select and add more than one at a time.


2 Answers

One solution is to not use external jars, but to put your jars into a project, and then use Add Jar(s) instead of Add External Jar(s).

This makes sense from the point of view of source control, you can add/remove dependencies as you need them. It also means that when you update one jar for a separate project, it'll not affect this one.

We've done this in the past, we had a single project which contained all of the jars, which were referred to in the build paths of other projects.

But now we use maven, so we don't need to do that any more.

like image 52
Matthew Farwell Avatar answered Oct 23 '22 02:10

Matthew Farwell


In eclipse, right-click the project, choose Properties, then Java Build Path, Libraries tab and select "Add Jars"... this will add it with a relative path. "Add External JARs" adds the jar with an absolute path which is not what you want.

like image 25
Igor Popov Avatar answered Oct 23 '22 03:10

Igor Popov