简体   繁体   English

Eclipse:将环境变量用于外部jar位置

[英]Eclipse: Use environment variable for external jar location

After hours of unsuccessful googling, I ask you: 经过几个小时的谷歌搜索不成功,我问你:

Situation: 情况:

My Eclipse Project uses "nedded.jar" so I added it to the build path. 我的Eclipse Project使用“nedded.jar”,所以我将它添加到构建路径中。 No problem. 没问题。

  • C:/dev/development/my_needed/nedded.jar 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. 但是“nedded.jar”的位置与环境变量DEVELOPMENT(= C:/ dev / development /)相关,因此可能会发生变化。 So, I need my Referenced Library path to be: 所以,我需要我的Referenced Library路径:

  • %DEVELOPMENT%/my_needed/nedded.jar %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). 也许我没有说清楚:这个项目是由MSVisual Studio(C ++)和Eclipse(Java)开发的。 Both are started from the Console. 两者都从控制台启动。 A prior executed script sets 3 major variables: DEVELOPMENT, RUNTIME, SOURCES to certain, changing paths. 先前执行的脚本设置3个主要变量:DEVELOPMENT,RUNTIME,SOURCES到某些不断变化的路径。

If I then start Eclipse from this shell, the path to my external libs shall be defined by %DEVELOPMENT%\\my_needed\\nedded.jar. 如果我从这个shell启动Eclipse,我的外部库的路径将由%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: 这会在你的.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%. 到目前为止很好,但它仍然不依赖于%DEVELOPMENT%。 What I need is: %DEVELOPMENT%/rxtx/RXTXcomm.jar 我需要的是:%DEVELOPMENT%/ rxtx / RXTXcomm.jar

Hope this is now clearer. 希望现在更清楚了。

You should declare a variable (Java Build Path -> Add Variable... -> Configure Variable ... -> New) to set the changing path on each system (eg FOO_BAR_HOME). 您应该声明一个变量(Java Build Path - > Add Variable ... - > Configure Variable ... - > New)来设置每个系统上的更改路径(例如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 (eg subfolder 'lib'). 或者,您可以将库放在项目中(例如子文件夹'lib')。 If you add the library from this location ('Add Jars...' NOT 'Add External Jars...') it will be added by relative path. 如果您从此位置添加库('添加Jars ...'NOT'添加外部JAR ...'),它将按相对路径添加。

I was searching for an answer to this as well with ant. 我正在寻找蚂蚁的答案。 Seems you can reference windows environment variables like so 似乎你可以像这样引用windows环境变量

<property environment="env"/>

Provide all environment variables as Ant properties prefixed by "env.". 将所有环境变量提供为以“env。”为前缀的Ant属性。 For example, CLASSPATH would be accessible in Ant as ${env.CLASSPATH}. 例如,可以在Ant中以$ {env.CLASSPATH}访问CLASSPATH。

I think you should be able to use 我认为你应该可以使用

${workspace_loc} 

or 要么

${resource_loc/<a name of your project/plug-in>/folder...}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM