MZimmerman6
MZimmerman6

Reputation: 8623

Getting ant to run java file

I am having trouble just creating something simple, and it does not seem that any website is clear on how to do this, and honestly I think it should be simple.

I have a bunch of java files for a project. I want to compile all of them, and then run each file with specific arguments.

Basically I want the order of operations to be something like this

javac prob1.java
javac prob2.java

java prob1 parameter
java prob2 parameter

But I want that in ant (build.xml).

I can do the compile part just fine with

<project default="compile"> 
    <target name="compile"> 
    <javac srcdir="." /> 
    </target> 
</project>

I just can not get it to run say prob1 with an argument. I imagine this is extremely easy, but every solution I have found, does not seem to work. Also note prob1.class and prob2.class are in the same directory.

Upvotes: 0

Views: 5339

Answers (1)

austin
austin

Reputation: 5876

This should work:

<target name="run">
    <java classname="prob1">
       <classpath>
           <pathelement location="."/>
        </classpath>
        <arg value="parameter" />
    </java>
    <java classname="prob2">
        <classpath>
           <pathelement location="."/>
        </classpath>
        <arg value="parameter" />
    </java>
</target>

Upvotes: 1

Related Questions