6

I'm trying to find a way to determine the Minecraft Server version (ie. 12w40b, 1.4.5, etc) of a given Jar file without needing to start up the entire server process? (I have full control over the server, as I'm writing a basic admin interface)

  • Is there a command-line argument I can append to my java -jar ... command to have minecraft only print the version and exit?
  • Can I extract the Jar file and look/grep for a specific file?

UPDATE I've created an issue with the Minecraft Bug Tracker here, we'll see what happens from the Mojang team. :)

3

You cannot do that with the ways you are outlining. You have 2 options:

  • Go by the date of the file, provides that you know when which version was released. You can find that here: http://www.minecraftwiki.net/wiki/Version_history
  • go by checksum of the version, provides that you have the checksum of each version in a table. You would have to create that first.
  • Start the server only until the first line of the output is reached, which outputs the version and kill it immediately.
  • Yeah, I already have the means to go with option 3, I'll probably just create a tmp dir to run that command in so I don't interfere with any of my active games/servers. – Dominic Barnes Dec 10 '12 at 15:24
  • 1
    You are assuming that he is using vanilla. Otherwise, the checksums would not be the same. – user28379 Dec 10 '12 at 21:05
  • Yes, since he is talking about the 12w40b snapshots, I assume he is using vanilla. Bukkit etc are using different version numbering. – uncovery Dec 11 '12 at 4:37
  • There is no sure-fire way to do this (other than with vanilla). Server jars can completely revamp how minecraft outputs stuff and return crazy version numbers or no version numbers at all! – Qix Dec 22 '12 at 22:19
0

Although this is an older question, it seems to still be relevant, as I just implemented a solution to this problem myself. I wrote a small bash script that, when passed a path to a minecraft server jar, extracts the MinecraftServer.class file to a temporary location, then extracts the String constants table using the javap tool (requires the JDK to be installed, rather than/in addition to the Java runtime), then filters the table down by looking for the expected Major.Minor.Rev version pattern. This solution works pretty reliably for now, with a couple of caveats:

  • Version number must be in Maj.Min.Rev format. Versioning tends to be pretty consistent once applied to a software application, but any changes will break the script.
  • Assumes no new additional string constants that match the expected format are present. A future change could very well introduce a "conflicting" string which would likely break the script.

To use the script, simply pass it the path to the minecraft server jar as the only argument. On success, the script returns 0 and outputs the version string to stdout. On failure, the script returns a non zero value.

#!/bin/bash
# Simple bash script that attempts to extract the version number from the
# minecraft server jar file.
#
# This script makes use of the Java dissassembler tool, provided with the
# Java JDK. You may need to explicitly install the JDK, since most server
# installs likely rely solely on the Java runtime (which does not include
# the development tools)

# Temporary file to extract the relevant class file into
TMP_CLASS=$(mktemp /tmp/mc-server-class.XXXXXXXXXXXXXXXX.class)

if [ -z "$1" ]; then
    >&2 echo "ERROR: You must specify a minecraft server jar file"
    exit 1
fi

# Ensure expected external dependencies are present
which unzip >/dev/null
if [ $? -ne 0 ]; then
    >&2 echo "ERROR: This utility requires 'unzip' to be installed"
    exit 2
fi

which javap >/dev/null
if [ $? -ne 0 ]; then
    >&2 echo "ERROR: This utility requires 'javap' to be installed"
    exit 2
fi

# Extract the main server class into the temporary file (we do this since
# javap apparently does not like to slurp from stdout)
unzip -p "$1" net/minecraft/server/MinecraftServer.class >$TMP_CLASS

# Use the java dissassembler tool to extract the constants table. We pipe the
# constants table into grep, and seperate out the Utf8 lines (all the String
# constact values). Next, we pipe the string constants to another grep, looking
# for the expected major.minor.revision number format. Finally, pipe the line
# for the version constant string into sed, to pare it down to a jsut the
# version string itself.
javap -c -verbose $TMP_CLASS | grep 'Utf8' | grep '[0-9]\{1,\}\.[0-9]\{1,\}\(\.[0-9]\{1,\}\)\{0,1\}' | sed -n 's/.*[^0-9.]\([0-9]\{1,\}\.[0-9]\{1,\}\(\.[0-9]\{1,\}\)\{0,1\}\).*/\1/p'

rm $TMP_CLASS
if [ $? -ne 0 ]; then
    >&2 echo "ERROR: Failed to remove temporary class file '${TMP_CLASS}'"
fi
0

Scripted one-liner approach without extra java packages, directories or created files:

unzip -p server.jar net/minecraft/server/MinecraftServer.class|strings|grep '[0-9]{1,}.[0-9]{1,}(.[0-9]{1,}){0,1}'

Successfully tested on a vanilla 1.13.2 server.jar.

[Apologies, I intended to simply post as a comment to Liam C.'s answer, as this is derivative (thanks for the unzip & grep regex!), but the system won't let me because I'm not legit enough yet.]

New contributor
DotA is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
-2

This is an old post, but here is an update:

Awnser to your question: No

Rather:

When you open the server you will get this line on the top of the server log:

[hh:mm:ss INFO]: Starting minecraft server version [version number]

You can also find the logs at serverfiles\logs\

-3

You can find the version of Minecraft running by typing about in the server console window.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.