I want to know whether we can have multiple JAVA_HOME on the same machine. If so, what are the steps to be followed to have multiple JAVA_HOME..? please help me with the answer...
CodePudding user response:
If you want to use a different version of Java for different projects you will need to specify it in the project. The JAVA_HOME can only be one version.
CodePudding user response:
in ubuntu, it works for me:
step 1: install muti version java.
step 2: example, I run muti java with maven.
edit file barchrc:
vim ~/.bashrcadd new line:
JAVA_HOME=/usr/java/openjdk/jdk-15export PATH=$PATH:/usr/local/nodejs/bin:$JAVA_HOME/binexport JAVA_HOMEalias mvn8="JAVA_HOME=/usr/lib/jvm/jdk1.8.0_261 && mvn"alias mvn11="JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64 && mvn"alias mvn15="JAVA_HOME=/usr/java/openjdk/jdk-15 && mvn"after, source file brach:
source ~/.bashrcrun test.
mvn8 clean compileormvn11 clean compile
CodePudding user response:
you can use jenv, with the export plugin enabled to change the java version and JAVA_HOME like
Configure global version
$ jenv global openjdk64-11.0.8
Configure local version (per directory)
$ jenv local openjdk64-11.0.8
Configure shell instance version
$ jenv shell openjdk64-11.0.8
To make sure JAVA_HOME is set, make sure to enable the export plugin:
jenv enable-plugin export
exec $SHELL -l
further information at https://www.jenv.be/

