我正在尝试获取我的主类路径上的所有内容以通过我的Ant buildscript写入文件:
<path id="main.class.path">
<fileset dir="${lib.main.dir}">
<include name="**/*.*"/>
</fileset>
</path>
Run Code Online (Sandbox Code Playgroud)
当我将鼠标悬停在上面时main.class.path,Ant/Eclipse会启动一个工具提示,显示该类路径上的项目:
C:\ Users \用户MYUSER \工作台\蚀\工作空间\的Myproj\lib中\主\蚂蚁的junit-1.6.5.jar
等(实际列表上有大约30个JAR.)
我希望将此列表写入我的dist/目录下名为deps.txt的文件中.
我被困了,因为我无法弄清楚如何制作main.class.path一个Ant变量,或者至少如何在<echo>任务中访问它:
<echo file="${dist.dir}/deps.txt" message="${???}"/>
Run Code Online (Sandbox Code Playgroud)
我是在这里的基地,还是远程关闭?!?
而对于那些你那里的人,而不是回答这个问题,只会评论你为什么要这样做?,我的回答很简单:我只想在我的JAR中使用一个小文本文件作为视觉提醒(对于我未来的我),它的依赖性是什么.
hmj*_*mjd 31
试试这个:
<pathconvert property="expanded.main.class.path" refid="main.class.path"/>
<target name="everything">
<echo message="${expanded.main.class.path}"
file="${dist.dir}/deps.txt"/>
</target>
Run Code Online (Sandbox Code Playgroud)
Reb*_*bse 14
直截了当的经历:
<echo file="${dist.dir}/deps.txt">${ant.refid:main.class.path}</echo>
<!-- or -->
<echo file="${dist.dir}/deps.txt">${toString:main.class.path}</echo>
Run Code Online (Sandbox Code Playgroud)
$ {ant.refid:main.class.path}或$ {toString:main.class.path}是一个csv属性,它保存路径中的所有项目,其嵌套文件集(一般来说是resourcecollections)用';分隔; "
请参阅Ant手动属性和PropertyHelpers
如果您需要另一个分隔符,则需要使用具有a的pathconvertpathsep attribute,即在deps.txt中使用每个文件后的新行pathsep="${line.separator}"