How can I run an application with a specific Java version? I have three Java versions intstalled:
myuser@mysystem:~$ sudo update-alternatives --config java
There are 3 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 auto mode
* 1 /opt/jdk-9.0.4/bin/java 1 manual mode
2 /opt/jdk1.8.0_162/bin/java 1 manual mode
3 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode
I have Java 9 set as default and I'd like to keep it that way. Still, an application named pdfsam doesn't seem to work properly with Java 9. What command is necessary to run it with openjdk (option 3)?
-
What is the command you use to run your application?TomVW– TomVW2018年05月22日 09:39:33 +00:00Commented May 22, 2018 at 9:39
2 Answers 2
You can run java with the absolute path to the installation
This would be your default /usr/bin/java installation
java -version
To change it, use the absolute path
/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java -version
If you're not running the java command directly, try setting the JAVA_HOME variable:
JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64/jre/" pdfsam
Comments
As I needed a specific version of Java for a specific application ("Jitsi Desktop" no more supported and works with JDK 8). The only way to get this specific version is to download it, uncompress and make application use it. In my case the JAVA_HOME environment variable does not working since the JDK is not really installed in the system.
So I found this simple method : install the JDK version needed and execute the specific application with specifying which version of JDK using with temporarily modifying the PATH environment variable.
In my case (the user must have right to read and execute the JDK) :
user@host:~$ PATH=/data/noinstall/jdk8u332-b09/bin/:$PATH jitsi
Note : adapt the path of the JDK's bin directory before the colon
So PATH is modified only during the execution of jitsi. Elsewhere during the execution or after the execution, PATH stay unchanged.
As update-alternatives --config java change the JDK globally I suppose this solution makes more comfortable the use cases with many different versions of JDK installed on the same system, dev, etc.
Based on this topic and my intuitions.