Minecraft and its mods are written in Java, and each Minecraft version needs a particular Java version. The wrong one is one of the most common reasons a server won't start.
The short answer
| Minecraft version | Java |
|---|---|
| 26.1 and newer | 25 |
| 1.20.5 to 1.21.x | 21 |
| 1.18 to 1.20.4 | 17 |
| 1.17 | 16 or 17 |
| 1.12 to 1.16.5 | 8 (some modded 1.16.5 packs run on 11) |
Future Minecraft releases may need newer Java again. The error message always says which version is needed.
Change it
Open the Startup tab, choose the Java version and restart the server. You can pick Java 8, 11, 17, 21 or 25.
Signs it's wrong
Too old:
java.lang.UnsupportedClassVersionError: ... 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
The class file version tells you what's needed: 61 is Java 17, 65 is Java 21, 69 is Java 25. See UnsupportedClassVersionError.
Too new (mostly old Forge versions on 1.16.5 and earlier): crashes mentioning ClassCastException with class loaders, or "Unsupported Java version" from the loader. Go back to Java 8.
Plugins and mods
A plugin or mod built for a newer Java than your server runs fails with the same UnsupportedClassVersionError, naming that plugin. Either run a newer Java (if your Minecraft version allows it) or use an older build of the plugin.
Questions
Should I always use the newest Java?
Use the newest one your Minecraft version and mods support. Very old versions, especially older Forge, break on new Java.
Do players need the same Java?
No. The Minecraft Launcher brings its own Java for players. This only matters for the server.