Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Eclipse classpath variable to replace absolute "sourcepath" path?

I would like to use an Eclipse classpath variable to resolve the attached source JAR file for a library in my classpath. This is the contents of my current ".classpath" file in Elcipse (Indigo):

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
  <classpathentry kind="src" path="src"/>
  <classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
  <classpathentry exported="true" kind="lib" path="lib/ApacheCommons/commons-logging.jar"/>
  <classpathentry exported="true" kind="lib" path="lib/Spring-WS/spring-ws-1.5.8-all.jar"/>

  <!-- [other entries] -->

  <classpathentry kind="output" path="bin"/>
</classpath>

When I now add a source JAR file for "spring-ws-1.5.8-all.jar", the ".classpath" files contents is:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
  <classpathentry kind="src" path="src"/>
  <classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
  <classpathentry exported="true" kind="lib" path="lib/ApacheCommons/commons-logging.jar"/>
  <classpathentry exported="true" kind="lib" path="lib/Spring-WS/spring-ws-1.5.8-all.jar"
    sourcepath="D:/dev/sources/spring-ws-1.5.8-sources.jar"/>

  <!-- [other entries] -->

  <classpathentry kind="output" path="bin"/>
</classpath>

As you can see, Eclipse added the "sourcepath" attribute to the "classpathentry" element with an absolute path.

Now my idea is to replace the absolute path with the classpath variable "SOURCE_PATH", which is correctly set to "D:/dev/sources".

(Please, don't ask why we have this setup or suggest we must change it; it is an old project and we are unfortunately not able/allowed to change the build structure).

I tried

sourcepath="SOURCE_PATH/spring-ws-1.5.8-sources.jar"

as well as

sourcepath="${SOURCE_PATH}/spring-ws-1.5.8-sources.jar"

but both variants do not work.

I seems, that I either use the wrong syntax or I don't understand the concept of classpath variables. Maybe the classpath variable can't be used for the "sourcepath" attribute?

Thanks a lot for your help!

like image 300
It's Leto Avatar asked Apr 28 '13 21:04

It's Leto


People also ask

What is Eclipse classpath file?

The . classpath maintains the project's source and target references for Java compilation and compressed file or project dependencies. This configuration is maintained through the Java Build Path page in the project's properties.

Where is the .classpath file?

classpath file is created in the project's root directory. If you created the project on an existing code-base, eclim will attempt to setup the . classpath file with any source code directories or libraries in the project.


2 Answers

I might not understand your question completely but it sounds like you added your jar file with an absolute path to begin with. Instead add it with a classpath variable.

Use the Project properties, select Java Build Path option. Then click on the Libraries tab. Then Add Variable.... If you haven't created your SOURCE_PATH classpath variable yet, you can do it from here by clicking the Configure Variables... button (just a shortcut to the proper workspace preference setting). Once configured you should see your SOURCE_PATH class path variable in the box at the top. You can click on it extend to Extend... it to a subfolder or a jar file.

like image 110
Tod Avatar answered Oct 21 '22 07:10

Tod


Using Tod's answer above, if you have lots of jars in lots of projects, you may find it easier to edit the .classpath files directly. Using a Java Build Path variable in .classpath changes the reference from:

<classpathentry kind="lib" path="/full/pathTo/Jar.jar"/>

to:

<classpathentry kind="var" path="NEW_PATH_VARIABLE/Jar.jar"/>
like image 40
Ian Morse Avatar answered Oct 21 '22 07:10

Ian Morse