jar_java_versions
This script will display the Java and class file versions used by the classes within the given JAR file.
If you use the optional second positive integer parameter (range: [5, n)) only non-matching versions will be displayed and if there is at least one mismatch the exit code will be 100
instead of 0
.
This script is useful to verify that you have not inadvertently forgotten the release option while building your classes if you want to target a specific Java version. |
Usage
$ curl -L -O -s https://repo1.maven.org/maven2/org/junit/jupiter/junit-jupiter-api/5.11.0/junit-jupiter-api-5.11.0.jar
$ jar_is_multi_release junit-jupiter-api-5.11.0.jar
0
$ scripts/java/jar_java_versions.sh junit-jupiter-api-5.11.0.jar
Java Version: 8; Class File Version: 52
$ scripts/java/jar_java_versions.sh junit-jupiter-api-5.11.0.jar 8
$ echo $?
0
$ scripts/java/jar_java_versions.sh junit-jupiter-api-5.11.0.jar 11
Java Version: 8; Class File Version: 52
$ echo $?
100
$ curl -L -O -s https://github.com/adoble/adr-j/releases/download/v3.3.1/adr-j.jar
$ jar_is_multi_release adr-j.jar
0
$ scripts/java/jar_java_versions.sh adr-j.jar
Java Version: 5; Class File Version: 49
Java Version: 8; Class File Version: 52
Java Version: 21; Class File Version: 65
$ echo $?
0
$ scripts/java/jar_java_versions.sh adr-j.jar 5
Java Version: 8; Class File Version: 52
Java Version: 21; Class File Version: 65
$ echo $?
100
$ scripts/java/jar_java_versions.sh adr-j.jar 8
Java Version: 5; Class File Version: 49
Java Version: 21; Class File Version: 65
$ echo $?
100
$ scripts/java/jar_java_versions.sh adr-j.jar 21
Java Version: 5; Class File Version: 49
Java Version: 8; Class File Version: 52
$ echo $?
100
$ scripts/java/jar_java_versions.sh adr-j.jar 22
Java Version: 5; Class File Version: 49
Java Version: 8; Class File Version: 52
Java Version: 21; Class File Version: 65
$ echo $?
100
$ curl -L -O -s https://repo1.maven.org/maven2/net/bytebuddy/byte-buddy/1.14.19/byte-buddy-1.14.19.jar
$ jar_is_multi_release byte-buddy-1.14.19.jar
1
$ scripts/java/jar_java_versions.sh byte-buddy-1.14.19.jar
Java Version: 5; Class File Version: 49
Java Version: 6; Class File Version: 50
$ scripts/java/jar_java_versions.sh byte-buddy-1.14.19.jar 5
Java Version: 6; Class File Version: 50
$ echo $?
100