[英]Ant exec command argument dealing with multiple files
I am using ant exec command to implement the less utility to view the source code of a bunch of .java files.我正在使用 ant exec 命令来实现 less 实用程序来查看一堆 .java 文件的源代码。 (I know that there are other ways to do this like using
concat
) (我知道还有其他方法可以做到这一点,比如使用
concat
)
So the call ant view
works if I specify only one file:因此,如果我仅指定一个文件,则调用
ant view
起作用:
<target name="view">
<exec executable="less" dir=".">
<arg value="Main.java"/>
</exec>
</target>
But if I change my code to <arg value="*.java"/>
to view all files, it actually searches for a file named *.java
.但是,如果我将代码更改为
<arg value="*.java"/>
以查看所有文件,它实际上会搜索名为*.java
的文件。
Apparently I can put a bunch of arg
's for each file, but is there a way to do this with one arg
?显然我可以为每个文件放置一堆
arg
,但是有没有办法用一个arg
做到这一点?
The *
glob is expanded by the shell on Unix-likes, that's why less doesn't do it itself. *
glob 由类 Unix 上的 shell 扩展,这就是为什么 less 本身不这样做。
Apart from <exec>
there is <apply>
which works on a resource collection:除了
<exec>
之外,还有<apply>
资源集合的<apply>
:
<apply executable="less" dir="." parallel="true" relative="true">
<fileset dir="." includes="*.java"/>
</apply>
You can use foreach
which requires ant-contrib您可以使用需要ant-contrib 的
foreach
<target name="view">
<foreach target="call-less" param="file">
<fileset dir="${src}" includes="**/*.java" />
</foreach>
</target>
<target name="call-less">
<exec executable="less">
<arg value="${file}" />
</exec>
</target>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.