Feature Request: Support for several java versions

Due to changes in requirements between the different minecraft server versions we are observing an increase in requests for how to support servers requiring differing java versions from each other. It seems we need a system in MineOS to select a different java version than standard installed.

I’m thinking a pulldown menu that lets you select the java version the minecraft server needs. For a new server it should autoselect the default version (system version), then store the selected version in server.config.

It may be that the best way to have other java versions would be to store them as profiles, and use the profile system for downloading and setting up runnable java versions under profiles/java/javaversion/bin so that MineOS can use them if selected.

3 Likes

Recently updated Java and now am unable to run pre 1.17 servers.
Spent most of the day trying to find a workaround and have pretty much given up.

I think this feature is necessary as of Minecraft 1.17

Ditto here. I’ve been able to install multiple versions of java following the instructions at the link below (but not doing the 3rd step to set it as default). But I’m stuck trying to configure MineOS to run a java version other than the default. Some ideas: (1) some type of ‘java version selector’ program that is in the path so that MineOS will run it, which will examine the command line arguments to select the proper version of java to run; (2) a jar program which runs the correct jar program with the correct java runtime; (3) using the command line arguments to somehow fake calling the correct executable using “&&”

Besides adding the feature to MineOS, which would be great, I think that potentially all three of the above techniques could work. I just don’t know enough about java or linux to be able to implement any of them successfully.

Ref: Upgrading to Java 15 from the MineOS Turnkey ISO

Multiple java version support is really needed now that Minecraft 1.17 only runs on Java 16, and prior versions of Minecraft (and/or modpacks) need older versions of Java.

Until we get official support, I did a little hack on a friends linux Mineos install. I added a script file named /usr/local/bin/java

Since /usr/local/bin is in the path before /usr/bin the mineos daemon will find this script before the system java. What the script does is look for a file named .jdk and if it exists it uses the contents as the location of the java executable to use. If not found, it uses the system default java. Then I created the .jdk files as needed in /var/games/minecraft/servers/XXX for those servers which needed a java version different from the system default. e.g. echo /usr/lib/jvm/java-16-openjdk-amd64/bin/java > .jdk

#!/bin/bash

JAVA=$( cat .jdk 2> /dev/null )

if [ -z ${JAVA} ]
then
  JAVA=/usr/bin/java
else
  echo JAVA is [${JAVA} "$@"]
fi

${JAVA} "$@"
2 Likes

This is a brilliant temporary solution. Hopefully something like this will be integrated into the UI in the near future.

Somehow this doesn’t work for me :thinking:

Could be because I am using the modified version of mineOS.

Hard to know what might be going wrong. First thing to check would be the PATH environment variable for whichever account runs your daemon process. Make sure /usr/local/bin is before wherever your java default is.

You can always run “java -version” to see what’s being found, with and without the .jdk file. Make sure you put the dot in the name ( dot j d k ). Also can add echo statements to the script, or even add “set -x” toward the top on the script.

Path shouldn’t be the problem as seen here. But it is still first running java16 and I have no clue why. And no other dirs have any java command in it. Also when I run the command file seperate it says “command not found”

Did you make the script executable? “chmod +x /usr/local/bin/java”
Is bash installed? Usually it is, but if not you may need to change the #!/bin/bash to #!/bin/sh

If it still won’t run directly, try “bash -x /usr/local/bin/java” and see what command it is failing at. The -x will make it output each line of the script as it executes it.

Seems to work now. Probably was the chmod not setup properly, Anyways thanks for the help!

https://discourse.codeemo.com/t/multiple-versions-of-java-on-mineos/4736/2

On a server-by-server basis, you can modify the Java binary invoked. See this post; changes are made to server.config

1 Like

Hey Fitz,
Thanks for the script, this seems like the solution I need.
I’ve created the script, but I need help ‘creating the jdk file’ for the different servers.
I can’t find /usr/lib/jvm/…
Can you give provide more detail on how to do that please.

Cheers,
srek

The script I made is not necessary. It is better to use the server.config method linked by hexparrot. Installing the JRE Is OS specific. Use your standard package manager to do that. For instance, on debian based systems you would do something like “sudo apt install openjdk-17-jre-headless”

[java]
java_binary=/path_to_java_goes_here/bin/java

1 Like

I personally think it’s better to download the version you want ot use and then point the service config to that one. No need to install it for the whole system. Especially if you run multiple servers and more than 1 use an older version and only 1 uses a different one.

Thanks that got it sorted, pretty simple but through the GUI would be nice.