尝试将 Java 升级到 Minecraft 服务器的最新版本 (v1.18) 时,我遇到了一些麻烦,因为服务器最初运行的是 Ubuntu 19.x,因此在找到允许我更新所有软件包并进行升级的地方后,我将其转换为 20.04。
在此之后,我安装了 JRE,这是显示我当前版本的相同命令:
mortimer@mineraft:/home/minecraft$ sudo apt-get install default-jre
Reading package lists... Done
Building dependency tree
Reading state information... Done
default-jre is already the newest version (2:1.11-72).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
JDK 也类似:
mortimer@mineraft:/home/minecraft$ sudo apt-get install default-jdk
Reading package lists... Done
Building dependency tree
Reading state information... Done
default-jdk is already the newest version (2:1.11-72).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
运行更新替代方案:
mortimer@mineraft:/home/minecraft$ sudo update-alternatives --config java
There are 4 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/jdk-16.0.1/bin/java 0 manual mode
* 4 /usr/local/java/jre1.8.0_311/bin/java 1 manual mode
Press <enter> to keep the current choice[*], or type selection number:
但如果我运行 Q&D 启动命令:
mortimer@mineraft:/home/minecraft$ cat start.sh
#!/bin/bash
sudo java -Xmx6G -Xms4G -jar /home/minecraft/spigot-1.18.jar nogui > /dev/console
我从服务器收到一条错误消息,指出:
mortimer@mineraft:/home/minecraft$ sudo ./start.sh
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/bukkit/craftbukkit/bootstrap/Main has been compiled by a more recent version of the Java Runtime (class file version 60.0), this version of the Java Runtime only recognizes class file versions up to 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:756)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:473)
at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:601)
mortimer@mineraft:/home/minecraft$
有人能解释一下我做错了什么吗?
谢谢
[编辑-添加 java -version]
mortimer@mineraft:/home/minecraft$ java -version
java version "1.8.0_311"
Java(TM) SE Runtime Environment (build 1.8.0_311-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.311-b11, mixed mode)
mortimer@mineraft:/home/minecraft$
答案1
Minecraft:Java 版 1.18 无法在 Java 8 上运行。它需要 Java 17。如果 Minecraft 是你使用 Java 的唯一用途,我建议卸载你现在拥有的版本:
sudo apt remove default-jre default-jdk
sudo apt autoremove
现在,安装 OpenJDK 17:
sudo apt update
sudo apt install openjdk-17-jre
我们不安装 JDK,因为它用于编译 Java 程序。您不需要安装它,而是运行一个程序(Minecraft),因此您只需要 JRE。
Minecraft 版本 | Java 版本 |
---|---|
1.16 | 16 |
1.17 | 16 |
1.18 | 17 |