Java 是否可以让 Ant 打印出特定目标的类路径?如果是这样,如何?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2430445/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 07:31:24  来源:igfitidea点击:

Is it possible to have Ant print out the classpath for a particular target? If so, how?

javaantclasspathtarget

提问by Daryl Spitzer

I'm trying to get a target to build that has quite a long list of <pathelement location="${xxx}"/>and <path refid="foo.class.path"/>elements in its <path id="bar.class.path">element (in the build.xml file). I keep getting "package com.somecompany.somepackage does not exist" errors, and I'm having a hard time chasing down these packages and making sure I've synced them from our repository.

我正在尝试构建一个目标,该目标在其元素(在 build.xml 文件中)中有很长的<pathelement location="${xxx}"/><path refid="foo.class.path"/>元素列表<path id="bar.class.path">。我不断收到“包 com.somecompany.somepackage 不存在”错误,而且我很难找到这些包并确保我已经从我们的存储库中同步了它们。

I'm new to this team so I'm unfamiliar with the build, but I would prefer to figure this out myself if possible (so I don't bother the other very busy team members). I have very limited experience with Ant.

我是这个团队的新手,所以我不熟悉构建,但如果可能的话,我更愿意自己解决这个问题(所以我不会打扰其他非常忙碌的团队成员)。我对 Ant 的经验非常有限。

I think it would save me quite a bit of time if I could have Ant print out the classpath for the target I'm trying to build.

我认为如果我可以让 Ant 打印出我正在尝试构建的目标的类路径,这将为我节省相当多的时间。

采纳答案by karoberts

Use the pathconverttask to convert a path to a property

使用pathconvert任务将路径转换为属性

<path id="classpath">
....
</path>

<pathconvert property="classpathProp" refid="classpath"/>

<echo>Classpath is ${classpathProp}</echo>

Docs for pathconvert.

pathconvert 的文档

回答by iain

This is even easier with versions of Ant > 1.6

对于 Ant > 1.6 的版本,这更容易

<echo>${toString:classpath}</echo>

See http://ant.apache.org/manual/using.html#pathshortcutfor more information

有关更多信息,请参阅http://ant.apache.org/manual/using.html#pathshortcut