Search code examples
javaserverminecraftbukkit

How to get the minecraft server version of paper or spigot or bukkit jar using java code


I want to get the version to change the java version automatically.

Because until 1.16 needs java 8 however from 1.17 to launch server needs java 17 etc.

I was tried get manifest and mainclass. and then, get mainclass's major version. but high version doesn't contain true data in jar. So it cannot get the true version.

I'm sorry for my bad english.

Thank you for reading.


Solution

  • Okay so presuming;

    1. Java application is running in an environment with a bukkit.jar file

    2. You need to retrieve the version of this .jar

    If you open a .jar with an archive explorer, like 7zip, you can browse through there..

    I went ahead and downloaded craftbukkit-1.19.2.jar and noticed inside of it's META-INF folder is a 'versions.list' file which contains a a single String

    a3e1a91200a28b55f64c43b7980830259798984389c782ab8e07364f2e1eb16a *craftbukkit-1.19.2-R0.1-SNAPSHOT.jar

    This seems like a good place to start, this String is likely unique in each build.

    Otherwise you could access the jar's Manifest and find something in there.

    reading MANIFEST.MF file from jar file using JAVA