If I were you then I would create function() in .profile
or .bashrc
for command prompt or terminal which will export JAVA_HOME
variable to Java8
or Java9
depending on whether I am running ant
or mvn
respectively.
Lets say your Java8 and Java9 are installed at below locations ...
- C:\Program Files\Java\jdk1.8.0_151\bin
- C:\Program Files\Java\jdk1.9.0_4\bin
Then your functions in .profile
or .bashrc
should be like this ...
For ant
and Java8 (here i am passing command line argument $1
to ant
command)...
runant() {
export JAVA_HOME="C:\Program Files\Java\jdk1.8.0_151\bin";
ant $1;
}
For mvn
and Java9 ...
runmvn() {
export JAVA_HOME="C:\Program Files\Java\jdk1.9.0_4\bin";
mvn clean install;
}
With the above functions, you can run ant
and mvn
from command prompt and JAVA_HOME
will be set appropriately ONLY for that specific run.