tags:

views:

554

answers:

2

I've got a executable JAR file. And I've got an Ant build script that compiles and then creates this JAR file. I would like a task to run the JAR file as well, but I've got a command line argument that needs to be passed to the JAR. It's a configuration file. The run target is below

<target name="run">
    <java jar="build/jar/ShoutGen.jar" fork="true"/>
    <arg line="/home/munderwo/workspace/ShoutGen-Java/ShoutGen.conf"/>
</target>

When I try to do this and run it from within Eclipse I get

Buildfile: /home/munderwo/workspace/ShoutGen-Java/build.xml
run:
     [java] No config file passed as an argument. Please pass a configuration file
     [java] Java Result: 16

BUILD FAILED
/home/munderwo/workspace/ShoutGen-Java/build.xml:24: Problem: failed to create task or type arg
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.

The error output from Java is my coded error meaning "you didn't pass an config file as an argument" which backs up the ant error of "Problem: failed to create task or type arg".

So how do you pass an argument to an executed JAR file from within Ant? Is this something your not supposed to do?

+9  A: 

The <arg> tag should be a child of the <java> tag. Like this:

<target name="run">
    <java jar="build/jar/ShoutGen.jar" fork="true">
        <arg line="/home/munderwo/workspace/ShoutGen-Java/ShoutGen.conf"/>
    </java>
</target>

In your question <arg> is a sibling of <java> and the argument line is never passed to the java command.

Asaph
+3  A: 

Your arg statement is not properly nested in the java task. It needs to be

<java jar="...">
  <arg line="..." />
</java>
Ajay