views:

58

answers:

3

I have an Ant task to call a java process that takes a file on the command line. I can pass the file directly to the java program but I can't figure out how to make Ant take the file on the command line.

Here's what I've got:

<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>

When I run this I get

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

(I searched all over for an answer to this as I'm sure I'm just missing something simple but didn't find anything. If there's an SO answer out there, please point me to it. Thanks)

+1  A: 

I've never seen the <run-standalone> task, but you can just use <java> to launch a Java class and nested <arg> to specify the arguments to the class.

Example:

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

Of course, make sure that the value in the property ${file} actually exists first.

matt b
+1  A: 

Looks like the file property is not set.

Define the property file before <run-standalone>

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

Also looks like you are using a user-defined macro or a custom task run-standalone. Because it is not a part of standad Ant, it's really hard to tell what this specific API expects.

Alexander Pogrebnyak
+2  A: 

Try to call ant this way:

ant FileProcessor -Dfile=<your path here>
tangens
System properties are the only was to access values specified on the ant command line from within the build.xml.
Mark