Is there a script to determine Minecraft Server Jar Version?

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


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.

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" [email protected]
  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!

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

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