2009-10-21 19 views
1

我有一个Ant任务来调用一个java进程,它在命令行上接受一个文件。我可以直接将文件传递给java程序,但我无法弄清楚如何让Ant在命令行上执行该文件。如何指定一个文件传递给由Ant任务运行的java进程?

下面是我得到了什么:

<target name="FileProcessor" description="Process a specified file"> 
    <run-standalone name="CheckClearer" main-class="com.blah.FileProcessor"> 
     <args> 
      <arg value="${file}"/> 
     </args> 
    </run-standalone> 
</target> 

当我运行此我得到

Exception in thread "main" java.io.FileNotFoundException: ${file} (No such file or directory) 

(我找遍了的答案,这是我敢肯定,我谢谢)

+0

你尝试添加'文件:$ {}文件'前'运行standalone'? – 2009-10-21 15:53:26

回答

1

我从来没有见过<run-standalone>任务,但您可以使用<java>启动Java类并嵌套<arg>以指定该类的参数。

例子:

<target name="FileProcessor" description="Process a specified file"> 
    <java classname="com.blah.FileProcessor"> 
     <classpath>...</classpath> 
     <arg file="${file}"/> 
    </java> 
</target> 

当然,确保在属性${file}的值实际上第一存在。

1

貌似不设置file属性。

定义属性file<run-standalone>

<property name="file" location="/path/to/file"/> 
<run-standalone> 
... 
</run-standalone> 

也像您使用的是用户自定义宏或自定义任务run-standalone。因为它不是标准版 Ant的一部分,所以很难说出这个特定API的期望。

2

尝试致电蚂蚁这样:

ant FileProcessor -Dfile=<your path here> 
+0

系统属性是唯一能够从build.xml中访问ant命令行上指定的值的。 – Mark 2009-10-21 16:24:19

相关问题