5

Problem summary

I'm trying to set up my raspberry pi 4 as a minecraft server as described here. I've installed the default version of java. The output from java -version is

openjdk version "17.0.11" 2024-04-16

The next step is to launch the server with the command

java -Xmx1024M -Xms1024M -jar server.jar

However, when I try this, I get the following error

 LinkageError occurred while loading main class net.minecraft.bundler.Main
        java.lang.UnsupportedClassVersionError: net/minecraft/bundler/Main has been compiled 
by a more recent version of the Java Runtime (class file version 65.0), 
this version of the Java Runtime only recognizes class file versions up to 61.0

I assume that this means that the minecraft server uses files written for a later version of Java?

If this is true, how can I get more recent versions of Java for raspberry pi OS?

I imaged the card just yesterday using the Raspberry Pi Imager and did apt update and upgrade.

Linux raspberrypi 6.6.20+rpt-rpi-v8 #1 SMP PREEMPT Debian 1:6.6.20-1+rpt1 (2024-03-07) aarch64

r.bot
  • 153
  • 1
  • 5

1 Answers1

6

a more recent version of the Java Runtime (class file version 65.0)

That's java 22 which is not available in current RaspiOS.

If this is the major purpose for the Pi, you could install an OS that does provide java 22. Unfortunately, this may not be easy as the latest on Ubuntu 24.04 is java 21. Java 22 is in Fedora 39+, which should be installable, but I cannot vouch for how easy that is or how well it works for various purposes (there are not a lot of such users, I think).

Your other choice is to try installing OpenJDK 22 directly:

https://jdk.java.net/22/

You need the 64-bit version of RaspiOS for this (from your question it looks like the kernel is, if you are not sure beyond that just check the output from file /bin/bash, there should be an "aarch64" in the line of output), and download the "Linux / AArch64" package from the link above. Put that in /opt and from there:

sudo tar -xzf openjdk-22.0.1_linux-aarch64_bin.tar.gz

This will take a few seconds. You'll end up with an /opt/jdk-22.0.1. Now:

sudo update-alternatives --install /usr/bin/java java /opt/jdk-22.0.1/bin/java 1
sudo update-alternatives --config java

Don't miss the whole first command, which ends in 1. The second should then give you a numbered list to choose from; pick the one corresponding to jdk-22, and (hopefully) viola. I tried this on a Pi 4 still running RaspiOS 11 (bullseye) and:

> java -version
openjdk version "22.0.1" 2024-04-16
OpenJDK Runtime Environment (build 22.0.1+8-16)
OpenJDK 64-Bit Server VM (build 22.0.1+8-16, mixed mode, sharing)

I'm not a minecraft user, but this should do the trick.

goldilocks
  • 60,325
  • 17
  • 117
  • 234