On running the following command:
ant targetname -Dk1=v1 -Dk2=v2
I want the command line parameters passed down to java
, like java whatever -Dk1=v1 -Dk2=v2
.
I need to access these parameters from Java code with System.getProperty
or System.getenv
.
What do I need to write in my ant build script to make this happen?
Or should I take some other approach altogether?
Not good in Ant Script but I do something like below :
If you are using Eclipse, you will get suggestions in popup under java tag. I got few more like :
<sysproperty/>, <syspropertyset></syspropertyset>, <jvmarg/>
I'm not sure exactly how you want to pass these values, but there are several mechanisms:
<sysproperty>
to pass system properties you need to set:<arg>
to pass command line arguments to your Java class<jvmarg>
to pass arguments to your Java command itselfThis:
Becomes:
Hope that example helps
Use the nested
<arg>
elements in your<java>
task: