I want to set an env variable inside my build.xml target
<target name="run-tenantManagement" depends="jar">
<property name="SIMV3.1" value="${SIMV3.1}" />
//now here i want to do something like setenv SIMV3.1 true
</target>
and Inside my java code, I want to access it using :
if("true".equals(System.getenv("SIMV3.1")){
//do something
}
Kindly suggest. I have tried many things but none of them worked.Also, there is no main() method as the framework is testng based and test cases are invoked using testNG.
Yes you can do this. Place your variable in a
build.properties
file and reference it in your build.xml. Then you can pass the variable... But I think it would be much better to use Maven Profiles if you need to have better control over multiple environment configurations.build.properties
build.xml
CLI
How are you running your program? If it is using exec with fork, then you can pass new environment to it
https://ant.apache.org/manual/Tasks/exec.html.
Example from the page..
Consider following build.xml file
and small java program
With out any command line:
With some arguments from command line:
Immutability: In ant, properties are immutable:
won't work.
Mutability: But variables are mutable, so this works:
Modified Code :