使用Eclipse classpath变量来替换绝对的"sourcepath"路径?

It'*_*eto 9 java eclipse build classpath

我想使用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>
Run Code Online (Sandbox Code Playgroud)

当我现在为"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>
Run Code Online (Sandbox Code Playgroud)

如您所见,Eclipse使用绝对路径将"sourcepath"属性添加到"classpathentry"元素.

现在我的想法是用类路径变量"SOURCE_PATH"替换绝对路径,该变量被正确设置为"D:/ dev/sources".

(请不要问为什么我们有这个设置或建议我们必须更改它;它是一个旧项目,遗憾的是我们不能/允许更改构建结构).

我试过了

sourcepath="SOURCE_PATH/spring-ws-1.5.8-sources.jar"
Run Code Online (Sandbox Code Playgroud)

以及

sourcepath="${SOURCE_PATH}/spring-ws-1.5.8-sources.jar"
Run Code Online (Sandbox Code Playgroud)

但这两种变体都不起作用.

我似乎,我要么使用错误的语法,要么我不理解类路径变量的概念.也许classpath变量不能用于"sourcepath"属性?

非常感谢你的帮助!

Tod*_*Tod 5

我可能完全不理解你的问题,但听起来你添加了一个带有绝对路径的jar文件.而是使用classpath变量添加它.

使用Project属性,选择Java Build Path选项.然后单击Libraries选项卡.然后, Add Variable....如果尚未创建SOURCE_PATH类路径变量,则可以通过单击Configure Variables...按钮(只是正确的工作区首选项设置的快捷方式)从此处执行此操作.配置完成后,您应该在顶部的框中看到您的SOURCE_PATH类路径变量.您可以单击它将其扩展到Extend...子文件夹或jar文件.


cpr*_*ger 0

您可以使用符号链接。Windows 还支持以 / 开头的路径。这是依赖于驱动器的。尝试cd /在命令提示符下进行验证。