passing command line arguments thru ant

J

jimgardener

hi
i have a java class which takes in 3 arguments,ie a foldername string,
an imagename string,and an integer.From command line i run this like
java myapp.PatternMaker myfolder samples/image1.jpg 5

I wanted to do this thru ant buildfile. so i put a target like

<target name="run" depends="compile">
<java classname="myapp.PatternMaker">
<classpath>
<pathelement location="${build}"/>
<pathelement path="mylib/somegraphics.jar"/>
</classpath>
<arg line="${myfolder} ${samples}/image1.jpg 5"/>

</java>
</target>


This lets me call ant run to run the program.But i have a need to run
the program with diff image names and diff integer values as arguments.
(The locations of myfolder and samples directories do not change),I
may need to run the code as

java myapp.PatternMaker myfolder samples/image2.jpg 8

Can someone tell me how i can do this ?I am a beginner to ant ..i
would like to have something like
ant run image2.jpg 8 to run the program with the above arguments.I
couldn't quite figure out how to do this.Can someone help?

thanks
jim

p.s: also i saw some warnings in ant manual to avoid usage of
<arg line ...Is there a better way i can pass the arguments?
 
D

Donkey Hottie

hi
i have a java class which takes in 3 arguments,ie a foldername string,
an imagename string,and an integer.From command line i run this like
java myapp.PatternMaker myfolder samples/image1.jpg 5

I wanted to do this thru ant buildfile. so i put a target like

<target name="run" depends="compile">
<java classname="myapp.PatternMaker">
<classpath>
<pathelement location="${build}"/>
<pathelement path="mylib/somegraphics.jar"/>
</classpath>
<arg line="${myfolder} ${samples}/image1.jpg 5"/>

</java>
</target>


This lets me call ant run to run the program.But i have a need to run
the program with diff image names and diff integer values as arguments.
(The locations of myfolder and samples directories do not change),I
may need to run the code as

java myapp.PatternMaker myfolder samples/image2.jpg 8

Can someone tell me how i can do this ?I am a beginner to ant ..i
would like to have something like
ant run image2.jpg 8 to run the program with the above arguments.I
couldn't quite figure out how to do this.Can someone help?

thanks
jim

p.s: also i saw some warnings in ant manual to avoid usage of
<arg line ...Is there a better way i can pass the arguments?

I'm not good with ant either, but I would try something like this

<target name="run" depends="compile">
<java classname="myapp.PatternMaker">
<classpath>
<pathelement location="${build}"/>
<pathelement path="mylib/somegraphics.jar"/>
</classpath>
<arg value="${myfolder} />
<arg value=${samples}/image1.jpg />
<arg value="1" />
<java classname="myapp.PatternMaker">
<classpath>
<pathelement location="${build}"/>
<pathelement path="mylib/somegraphics.jar"/>
</classpath>
<arg value="${myfolder} />
<arg value=${samples}/image1.jpg />
<arg value="2" />
</java>
<java classname="myapp.PatternMaker">
<classpath>
<pathelement location="${build}"/>
<pathelement path="mylib/somegraphics.jar"/>
</classpath>
<arg value="${myfolder} />
<arg value=${samples}/image1.jpg />
<arg value="3" />
<!-- and so on... -->
</java>
</target>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top