简体   繁体   中英

How do I specify a file to pass to a java process run by an Ant task?

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)

尝试以这种方式调用ant:

ant FileProcessor -Dfile=<your path here> 

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM