我想使用 Eclipse 类路径变量来解析类路径中库的附加源 JAR 文件。这是我当前在 Elcipse (Indigo) 中的“.classpath”文件的内容:
<?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>
当我现在为“spring-ws-1.5.8-all.jar”添加源 JAR 文件时,“.classpath”文件内容为:
<?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>
如您所见,Eclipse 将“sourcepath”属性添加到具有绝对路径的“classpathentry”元素。
现在我的想法是用类路径变量“SOURCE_PATH”替换绝对路径,该变量正确设置为“D:/dev/sources”。
(请不要问我们为什么有这个设置或建议我们必须更改它;这是一个旧项目,很遗憾,我们不能/不允许更改构建结构)。
我试过了
sourcepath="SOURCE_PATH/spring-ws-1.5.8-sources.jar"
还有
sourcepath="${SOURCE_PATH}/spring-ws-1.5.8-sources.jar"
但这两种变体都不起作用。
看来,我要么使用了错误的语法,要么我不理解类路径变量的概念。也许类路径变量不能用于“sourcepath”属性?
非常感谢您的帮助!
最佳答案
我可能不完全理解你的问题,但听起来你添加了带有绝对路径的 jar 文件。而是使用类路径变量添加它。
使用项目属性,选择Java Build Path
选项。然后单击 Libraries
选项卡。然后 Add Variable....
如果您还没有创建 SOURCE_PATH 类路径变量,您可以从这里单击 Configure Variables...
按钮(只需正确工作区首选项设置的快捷方式)。配置完成后,您应该会在顶部的框中看到您的 SOURCE_PATH 类路径变量。您可以单击它扩展到 Extend...
到子文件夹或 jar 文件。
关于java - 使用 Eclipse 类路径变量替换绝对路径 "sourcepath"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16268375/