4

After hours of unsuccessful googling, I ask you:

Situation:

My Eclipse Project uses "nedded.jar" so I added it to the build path. No problem.

  • C:/dev/development/my_needed/nedded.jar

But the location of "nedded.jar" is relative to the environment variable DEVELOPMENT ( =C:/dev/development/ ) and therefore may change. So, I need my Referenced Library path to be:

  • %DEVELOPMENT%/my_needed/nedded.jar

I could not find the syntax to accomplish that. Ideas?

EDIT:

Maybe I did not make myself clear enough: This Project is developed by MSVisual Studio(C++) and Eclipse(Java). Both are started from the Console. A prior executed script sets 3 major variables: DEVELOPMENT, RUNTIME, SOURCES to certain, changing paths.

If I then start Eclipse from this shell, the path to my external libs shall be defined by %DEVELOPMENT%\my_needed\nedded.jar.

I have found a half way solution (somewhere): added a new folder --> advanced --> link to alternate location (linked folder).

this adds you an entry in your .project, which I also get, when I checkout my project:

<linkedResources>
   <link>
   <name>lib/RXTXcomm.jar</name>
   <type>1</type>
     <locationURI>PARENT-4-PROJECT_LOC/Development/rxtx/RXTXcomm.jar</locationURI>
   </link>
</linkedResources>

Nice so far, but it still does not depend on %DEVELOPMENT%. What I need is: %DEVELOPMENT%/rxtx/RXTXcomm.jar

Hope this is now clearer.

kc2001
  • 5,008
  • 4
  • 51
  • 92
LalaBox
  • 243
  • 2
  • 4
  • 10
  • Have you read http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.platform.doc.user%2Fconcepts%2Fcpathvars.htm – Leonard Brünings Oct 29 '13 at 13:50
  • Yes, no Help since I donn't want to refere to Eclipse internal environment variables. "${env_var}" can only be used in run/debug configuration. In ant script, I can refere to ". I want to checkout the project to any place in the filesystem, set the environment variables, start Eclipse, import the project and voila: all external libs are found automatically! – LalaBox Oct 30 '13 at 12:32
  • Helpfull approaches: [Post_1](http://stackoverflow.com/questions/1427048/how-can-i-add-build-path-items-to-eclipse-3-5-using-relative-paths), [Post_2](http://stackoverflow.com/questions/7742015/how-do-i-use-environment-variables-in-an-eclipse-classpath-file) – LalaBox Oct 30 '13 at 13:17

2 Answers2

4

You should declare a variable (Java Build Path -> Add Variable... -> Configure Variable ... -> New) to set the changing path on each system (e.g. FOO_BAR_HOME).

Then you can add the variable to the Libraries section and edit it to point to your library, like:

%FOO_BAR_HOME%/lib/foobar.jar

Take a look at the existing variables for usage.

Alternatively you can place the library inside the project (e.g. subfolder 'lib'). If you add the library from this location ('Add Jars...' NOT 'Add External Jars...') it will be added by relative path.

Damien
  • 1,161
  • 2
  • 19
  • 31
  • 1
    +1 for helping me out. Here's something to add (for Eclipse 3.6.2, at least)... After adding your FOO_BAR_HOME VARIABLE, you can edit the Java Build Path for your project. From the Libraries tab, click "Add Variable", select your FOO_BAR_HOME variable, and click the "Extend" button. Then, navigate to your jar file and select it. Your .classpath file will end up with a path relative to your FOO_BAR_HOME variable. – kc2001 Apr 03 '14 at 18:41
0

I was searching for an answer to this as well with ant. Seems you can reference windows environment variables like so

<property environment="env"/>

Provide all environment variables as Ant properties prefixed by "env.". For example, CLASSPATH would be accessible in Ant as ${env.CLASSPATH}.

Alao
  • 390
  • 5
  • 11