Concurrent Java Versions on Ubuntu

Tutorials, tips and tricks.

Moderator: moderators

Concurrent Java Versions on Ubuntu

Postby treed873 » Mon Jan 04, 2021 3:24 pm

As of this writing, Subsonic requires Java 8. But because of security flaws, and other applications moving away from working on this old version, and in my case Minecraft. So to keep both Subsonic and Minecraft on the same server, I needed to run 2 different versions of Java concurrently. I set the default Java version for my system to Java 11 with this command:
Code: Select all
sudo update-alternatives --config java

Which will bring up the installed versions of Java to choose from:
Code: Select all
There are 3 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                            Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-11-openjdk-amd64/bin/java      1111      auto mode
  1            /usr/lib/jvm/java-11-openjdk-amd64/bin/java      1111      manual mode
  2            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      manual mode
  3            /usr/lib/jvm/java-9-openjdk-amd64/bin/java       1091      manual mode

Press <enter> to keep the current choice[*], or type selection number:

Currently I have java-11-openjdk-amd64/bin/java selected, which is what I want for the system and for Minecraft. Subsonic does not work with java 11 so I need to edit the start up script to use Java 8 instead. To do this I will need to edit subsonic.sh located in /usr/share/subsonic/. To do this type in sudo nano /usr/share/subsonic/subsonic.sh and edit the following section:
Code: Select all
# Use JAVA_HOME if set, otherwise assume java is in the path.
JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
if [ -e "${JAVA_HOME}" ]
    then
    JAVA=${JAVA_HOME}/bin/java

The line JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 is what defines the java version, which before i edited it had JAVA=java. Now you will want to verify your path to the version of Java needed which can be done with the previous update-alternatives command.
Once you edit your subsonic.sh file, restart the service:
Code: Select all
sudo service subsonic restart

I am running Ubuntu 16.04 on my server so your mileage may vary.
treed873
 
Posts: 7
Joined: Mon Dec 21, 2020 12:48 pm

Return to Tutorials

Who is online

Users browsing this forum: No registered users and 8 guests