8

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. :)

4

If you are on MacOSX or Linux, I think this command does pretty much what you want:

unzip -p server.jar version.json | grep "name"

In my case it responds with "name": "1.14.4",

If you are on Windows I assume you could do something similar with PowerShell

| improve this answer | |
  • and... cut -d\" -f4 or similar awk field extraction if you feel confident. – mckenzm May 18 at 21:25
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.
| improve this answer | |
  • 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 - MONICA WAS MISTREATED Dec 22 '12 at 22:19
1

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
| improve this answer | |
1

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.]

| improve this answer | |
1

Ubuntu 16.04
GNU bash, version 4.4.20

I know this is an old thread but I love Minecraft and times have changed quite a bit since 2012. Today ... you can do anything. I did a little research and wrote this in bash. It's not pretty but shellcheck likes it and you don't need any Minecraft files to do any comparisons.

#!/bin/bash

#= Variables
mcVerTxt="mc_version.txt"
mcTmpDir="/tmp/mc-version"
mcVerJson="${mcTmpDir}/version_manifest.json"
mcURL="https://launchermeta.mojang.com/mc/game/version_manifest.json"

#= Download Manifest
mkdir -p "$mcTmpDir"
wget -q "$mcURL" -O "$mcVerJson"
python -m json.tool "$mcVerJson" > "$mcVerJson".temp
mcVersionNew="$(sed '3q;d' "$mcVerJson".temp | sed 's/release//g; s/"//g; s/://g; s/,//g; s/[\t ]//g;/^$/d')"
mcVersionOld="$(cat "$mcVerTxt")"

#= Compare + Notify
if (( $(echo "$mcVersionNew $mcVersionOld" | awk '{print ($1 > $2)}') )); then
  { echo ""; echo "Update Time! The latest Minecraft Version is $mcVersionNew and we are running $mcVersionOld!"; echo ""; }
  # echo "Update Time! The latest Minecraft Version is $mcVersionNew and we are running $mcVersionOld!" | mail -s "Minecraft Has A New Version - $mcVersionNew" user@domain.com
  echo "$mcVersionNew" > "$mcVerTxt"
fi

#= Clean Up
rm -rf "$mcTmpDir"

So let's say we are running version 1.14.4 on your server. Keep a file with the version number inside. The script is looking for a file named "mc_version.txt". After it downloads the Minecraft manifest it compares the latest version against the version inside the "mc_version.txt" file. If it is different, it prints a message and updates the "mc_version.txt" file. You can then download the minecraft_server.jar file. The URL is inside the manifest file. Uncomment line 18 and it sends you an email. Place it on a cronjob and you are all set.

root@work /home/minecraft # bash .minecraft_version_checker.sh

Update Time! The latest Minecraft Version is 1.15.1 and we are running 1.14.4!
| improve this answer | |
0

Extracting the jar file of the server you can find a file named version.json. There you can find a lot of informations about the version of the server.

| improve this answer | |
-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\

| improve this answer | |
-3

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

| improve this answer | |

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.