简体   繁体   English

.classpath xml中的环境变量

[英]Environmental Variables in .classpath xml

I've this line in .classpath file in Eclipse (Dynamic Web Project). 我在Eclipse(Dynamic Web Project)中的.classpath文件中有这一行。 I got this by adding an external jar from "build path" option. 我是通过从“构建路径”选项添加一个外部jar来实现的。

<classpathentry kind="lib" path="D:/apache-tomcat-7.0.55/lib/some.jar" sourcepath="/Scrubber"/>

But I already have CATALINA_HOME set in my system. 但是我已经在系统中设置了CATALINA_HOME。 I want to replace path="D:/apache-tomcat-7.0.55/lib/some.jar" to path="[CATALINA_HOME]/lib/some.jar" 我想将path="D:/apache-tomcat-7.0.55/lib/some.jar"替换为path="[CATALINA_HOME]/lib/some.jar"

What is the correct syntax for it. 正确的语法是什么? I tried 我试过了

path="${CATALINA_HOME}/lib/some.jar"

path="${env:CATALINA_HOME}/lib/some.jar"

path="${env.CATALINA_HOME}/lib/some.jar"

path="${catalina.home}/lib/some.jar"

path="${catalina.base}/lib/some.jar"

None of them worked for me. 他们都没有为我工作。

The class path entry will not resolve environment variables so this won't work. 类路径条目将无法解析环境变量,因此将无法使用。

The closest you can get is to use the Eclipse Preferences 'Java > Build Path > Classpath Variables' to define a similar CATALINA_HOME variable inside Eclipse. 最接近的方法是使用Eclipse首选项“ Java>构建路径>类路径变量”在Eclipse中定义类似的CATALINA_HOME变量。

Once you have the Eclipe Classpath Variable defines you can use the 'Add Variable...' button on the 'Java Build Path' property page in the 'Libraries' section. 一旦定义了Eclipe类路径变量,就可以使用“库”部分中“ Java构建路径”属性页上的“添加变量...”按钮。

This will give you a class path entry looking like: 这将为您提供一个类路径条目,如下所示:

<classpathentry kind="var" path="CATALINA_HOME/lib/some.jar"/>

note that the 'kind' is 'var' rather than 'lib'. 请注意,“种类”是“ var”而不是“ lib”。

You either need to set a global variable on Eclipse level or on project level. 您需要在Eclipse级别或项目级别设置全局变量。 Learn how to do it in Eclipse docs. 在Eclipse文档中学习如何做到这一点。 Basically you need to go to Run -> Run Configurations... and Select tab "Environment".The relevant article is here . 基本上,您需要转到运行->运行配置...,然后选择选项卡“环境”。相关文章在这里

To use your variable: (based on a system environment variable) select Add variable string, in .classpath type: ${env_var:your-environment-variable-name}/path-to-jar . 要使用您的变量:(基于系统环境变量)选择添加变量字符串,.classpath类型: ${env_var:your-environment-variable-name}/path-to-jar For example, if your system environment variable is MYVAR and the JAR file is under subdir/myfile.jar, you should type ${env_var:MYVAR}/subdir/myfile.jar . 例如,如果您的系统环境变量为MYVAR且JAR文件位于subdir / myfile.jar下,则应键入${env_var:MYVAR}/subdir/myfile.jar

在此处输入图片说明

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

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