How can I find out which version of java the jar file I have is available?
To tell the truth, the jar file itself does not have a build version. A jar file is just an archive of class files, properties files and other files. For example, can a jar be a relative of tar or zip? Therefore, to find out if the jar file is available for a particular version of Java, you should not look at the version of the jar file itself, but what version of javac the class file contained in that jar file was built with. I need to take a look.
commons-collections4-4.4.jar (Apache Commons Collections v.4.4) is available from which version as an example of the investigation method. I will investigate whether it is.
First, use the
jar command to extract the contents of the jar file.
$ jar xf commons-collections4-4.4.jar
You should find multiple class files stored in the jar file. Here, we will use
./org/apache/commons/collections4/ArrayStack.class as a sample.
$ find . -name "*.class" | head -n1 ./org/apache/commons/collections4/ArrayStack.class
I'd like to find out which version of javac
./org/apache/commons/collections4/ArrayStack.class was built with, but the quickest way is to use the
file command. In this case, it is obvious that it is built with Java 8.
$ file ./org/apache/commons/collections4/ArrayStack.class ./org/apache/commons/collections4/ArrayStack.class: compiled Java class data, version 52.0 (Java 1.8)
javap in an environment without the
$ javap -v ./org/apache/commons/collections4/ArrayStack.class | grep major major version: 52
javap is a command to disassemble a class file, and if you add the
-v option, detailed information is output, and version information is mixed in it. This is separated by
grep. The value
major version: 52 displayed here points to Java 8. For the correspondence between this
major version and Java version, please refer to the next page, which is well organized → [Wikipedia: Java class file](https://en.wikipedia.org/wiki/ Java_class_file)