使用 Eclipse 类路径变量替换绝对“源路径”路径?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16268375/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Use Eclipse classpath variable to replace absolute "sourcepath" path?
提问by It's Leto
I would like to use an Eclipse classpath variable to resolve the attached source JAR file for a library in my classpath. This is the contents of my current ".classpath" file in Elcipse (Indigo):
我想使用 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>
When I now add a source JAR file for "spring-ws-1.5.8-all.jar", the ".classpath" files contents is:
当我现在为“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>
As you can see, Eclipse added the "sourcepath" attribute to the "classpathentry" element with an absolute path.
如您所见,Eclipse 向带有绝对路径的“classpathentry”元素添加了“sourcepath”属性。
Now my idea is to replace the absolute path with the classpath variable "SOURCE_PATH", which is correctly set to "D:/dev/sources".
现在我的想法是用类路径变量“SOURCE_PATH”替换绝对路径,该变量正确设置为“D:/dev/sources”。
(Please, don't ask why we have this setup or suggest we must change it; it is an old project and we are unfortunately not able/allowed to change the build structure).
(请不要问我们为什么要进行此设置或建议我们必须更改它;这是一个旧项目,遗憾的是我们无法/不允许更改构建结构)。
I tried
我试过
sourcepath="SOURCE_PATH/spring-ws-1.5.8-sources.jar"
as well as
也
sourcepath="${SOURCE_PATH}/spring-ws-1.5.8-sources.jar"
but both variants do not work.
但两种变体都不起作用。
I seems, that I either use the wrong syntax or I don't understand the concept of classpath variables. Maybe the classpath variable can't be used for the "sourcepath" attribute?
我似乎要么使用了错误的语法,要么我不理解类路径变量的概念。也许类路径变量不能用于“源路径”属性?
Thanks a lot for your help!
非常感谢你的帮助!
回答by Tod
I might not understand your question completely but it sounds like you added your jar file with an absolute path to begin with. Instead add it with a classpath variable.
我可能不完全理解你的问题,但听起来你添加了带有绝对路径的 jar 文件。而是使用类路径变量添加它。
Use the Project properties, select Java Build Path
option. Then click on the Libraries
tab. Then Add Variable....
If you haven't created your SOURCE_PATH classpath variable yet, you can do it from here by clicking the Configure Variables...
button (just a shortcut to the proper workspace preference setting). Once configured you should see your SOURCE_PATH class path variable in the box at the top. You can click on it extend to Extend...
it to a subfolder or a jar file.
使用项目属性,选择Java Build Path
选项。然后单击Libraries
选项卡。然后, Add Variable....
如果您还没有创建您的 SOURCE_PATH 类路径变量,您可以从这里单击Configure Variables...
按钮(只是正确工作区首选项设置的快捷方式)。配置完成后,您应该会在顶部的框中看到 SOURCE_PATH 类路径变量。您可以单击它扩展到Extend...
子文件夹或 jar 文件。
回答by Ian Morse
Using Tod's answer above, if you have lots of jars in lots of projects, you may find it easier to edit the .classpath files directly. Using a Java Build Path variable in .classpath changes the reference from:
使用上面 Tod 的回答,如果您在很多项目中有很多 jar,您可能会发现直接编辑 .classpath 文件会更容易。在 .classpath 中使用 Java Build Path 变量会将引用更改为:
<classpathentry kind="lib" path="/full/pathTo/Jar.jar"/>
to:
到:
<classpathentry kind="var" path="NEW_PATH_VARIABLE/Jar.jar"/>
回答by cproinger
You could use a symbolic link. Windows also supports paths starting with /. This is drive dependent. Try cd /
on the Command Prompt to verify.
您可以使用符号链接。Windows 还支持以 / 开头的路径。这取决于驱动器。尝试cd /
在命令提示符下进行验证。