I have a CentOs machine where Java 8 and Java 11 is installed. Some (command line) programs need Java 8 because they did not moved to Java 11 yet, others need Java 11.
Is there a way to switch Java version before starting a command line program?
I have a CentOs machine where Java 8 and Java 11 is installed. Some (command line) programs need Java 8 because they did not moved to Java 11 yet, others need Java 11.
Is there a way to switch Java version before starting a command line program?
If you can specify the java command to use, in many cases that will be sufficient; for example, using the OpenJDK packages,
/usr/lib/jvm/java-1.8.0/bin/java
will start the Java 8 VM,
/usr/lib/jvm/java-11/bin/java
will start the Java 11 VM.
In some cases, or if you can’t specify the java command to use, you’ll also need to set JAVA_HOME, to the directory containing bin (/usr/lib/jvm/java-1.8.0 or /usr/lib/jvm/java-11 following the examples above).
/usr/bin/java note that the alternatives system, if employed, does not respect JAVA_HOME. See https://unix.stackexchange.com/a/419023/5132 for a lot more on this.
– JdeBP
Dec 18 '19 at 14:14
/full/path/to/javain a script. – xenoid Dec 18 '19 at 12:27