Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pass arguments to java through ant

Tags:

java

ant

I want to pass command line arguments to my java program that is invoked through a fake ant (we have our own ant script in perl which at some point calls the actual ant). So what I want to do is invoke my program like this :

./ant program_name arg1 arg2

Right now I have an ant target for my program but instead of passing the arguments from the command line I am hard-coding them into the build file like this :

<arg line="arg1 arg2"/>

Any ideas on how can I use variables in the build file and load them from the command line arguments and then use them in my java program ?

like image 739
comatose Avatar asked Oct 07 '22 09:10

comatose


1 Answers

The easiest might be to have your script turn then into system properties through -D.

Your ant build file can then use those to set ant properties that can be set in the <arg> tag (or referenced directly, although my preference would be to set ant properties, but that may be more out of habit than for any technical reason).

like image 155
Dave Newton Avatar answered Oct 11 '22 11:10

Dave Newton