I am new to Ant and any help will be appreciated.
What I want to do is:
When I am invoking an Ant target, I am doing :
ant -DSIMV3.1=true run-tenantManagement
Now Inside build.xml, I have:
<target name="run-tenantManagement" depends="jar">
<property name="SIMV3.1" value="${SIMV3.1}" />
...
</target>
Now I want the value of the property SIMV3.1 to be visible inside my java code. Because in my java code, I want to set a condition that:
if(SIMV3.1==true){
//do something
}else{
//do something else
}
Kindly help.
Another approach that's more persistent as far as the property value in your target build (i.e. the resulting jar file) is to have ant write the property value to a resource file that gets included in the target jar file. This gives the property value that gets set during the build a better lifespan (for lack of a better word) so that it can be made available in the project's (i.e. build's) products. For instance, an example ant file may look like:
The condition task defaults the property value to false if it's not provided and the resources tasks writes the property value to the resource file that will be included in the jar file (in the build task). Therefore building like this:
will result in a "true" value being written to the SIMV3.1 file in the resources package. Invoking ant without specifying the property will result in a default property of false being written to that resource file.
In the code this resource can be accessed via InputStream by reading the first (and only) line from the file and parsing that line using the Boolean class like so:
You can make use of sysproperty in java ant task to set the property.
This can be read in java class as below,