I want to find out which version of java the jar file I have is available

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.

Here, 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)

Use javap in an environment without the file command.

$ 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)

Recommended Posts

I want to find out which version of java the jar file I have is available
How to find out the Java version of a compiled class file
I want to find the MD5 checksum of a file in Java and get the result as a string in hexadecimal notation.
I want to find out if the specified character string is supported by the target character code
Find out the list of fonts available in AWS Lambda + Java
I want to get the field name of the [Java] field. (Old tale tone)
I want to find out what character the character string appears from the left
JAVA: jar, aar, view the contents of the file
I want to output the day of the week
I want to var_dump the contents of the intent
Try the free version of Progate [Java I]
[Java] I want to calculate the difference from the date
[Java] Check the JDK version of the built war file
I want to know the answer of the rock-paper-scissors app
I want to display the name of the poster of the comment
[Java] Get the file in the jar regardless of the environment
I want to be aware of the contents of variables!
I want to return the scroll position of UITableView!
I tried to find out what changed in Java 9
Even if I want to convert the contents of a data object to JSON in Java, there is a circular reference ...
Generate and execute Jar file of Java file belonging to package
I tried to summarize the basics of kotlin and java
(´-`) .. oO (I want to easily find the standard output "Hello".
I want to expand the clickable part of the link_to method
I want to change the log output settings of UtilLoggingJdbcLogger
I want to use the Java 8 DateTime API slowly (now)
I want to get a list of the contents of a zip file and its uncompressed size
Java: The problem of which is faster, stream or loop
How to change the contents of the jar file without decompressing
[Java] I definitely want to connect MySQL !!! ~ About getting JDBC driver and JAR file location ~
I want to narrow down the display of docker ps
[Ruby] I want to reverse the order of the hash table
I want to temporarily disable the swipe gesture of UIPageViewController
I want to simplify the conditional if-else statement in Java
I want to judge the necessity of testing by comparing the difference of class files when refactoring Java
Comparison of version strings (Java implementation) when you want to branch the process between two versions
I want to make the frame of the text box red when there is an input error
I want to understand the flow of Spring processing request parameters
I want to return to the previous screen with kotlin and java!
The story of Collectors.groupingBy that I want to keep for posterity
Want to know what Ruby n is the power of 2? (Power judgment of 2)
[Eclipse] I want to open the same file twice [Split editor]
The milliseconds to set in /lib/calendars.properties of Java jre is UTC
I want to limit the input by narrowing the range of numbers
I tried to summarize the methods of Java String and StringBuilder
[Java] I want to perform distinct with the key in the object
I want to control the default error message of Spring Boot
I made a tool to output the difference of CSV file
I want to change the value of Attribute in Selenium of Ruby
I was addicted to the API version min23 setting of registerTorchCallback
Is the version of Elasticsearch you are using compatible with Java 11?
How to get the length of an audio file in java
Replace the contents of the Jar file
[Java version] The story of serialization
I want to display the number of orders for today using datetime.
The story of forgetting to close a file in Java and failing
[Java Servlet] The road of Senri is also one step to the first
I want to display images with REST Controller of Java and Spring!
I want to know the JSP of the open portlet when developing Liferay
[Ruby] I want to extract only the value of the hash and only the key
[Introduction to Java] I tried to summarize the knowledge that I think is essential