How to check jar file version?

I am currently working on a Polish J2ME application, just improving it. I find it difficult to find the exact version of the jar file. Is there a way to find the version of the jar file for import made in the class? I mean, if you have something, import xyz; can we know what version of jar xy package belongs to?

+75
jar executable-jar version
Apr 29 2018-11-11T00:
source share
10 answers

Uncompress the JAR file and find the manifest file ( META-INF\MANIFEST.MF ). The manifest file of the JAR file may contain a version number (but the option is not always specified).

+65
Apr 29 2018-11-11T00:
source share

You need to unzip it and check its META-INF/MANIFEST.MF file, for example

 unzip -p file.jar | head 

or more specifically:

 unzip -p file.jar META-INF/MANIFEST.MF 
+43
Jul 11 '16 at 18:11
source share

To expand the answers above, inside the META-INF / MANIFEST.MF file in the JAR, you will most likely see the line: Manifest-Version: 1.0 ← This is NOT the banner version number

You need to look for the Implementation-Version , which, if present, is a free text string that is fully associated with the author of the JAR, depending on what you find there. See Also Oracle Docs and Package Version Specification.

+24
May 2 '14 at 20:07
source share

Just to complete the above answer.

The manifest file is inside the jar on the path META-INF\MANIFEST.MF .

You can view the contents of jar in any archiver that supports zip.

+17
Dec 22 '11 at 16:23
source share

Each jar version has a unique checksum. You can calculate the checksum for you jar (which did not have version information) and compare it with different versions of the jar. We can also search for a bank using a checksum.

Submit this question to calculate the checksum: What is the best way to calculate the checksum for the file that is on my machine?

+11
Apr 04 '13 at 15:59
source share

Basically you should use the java.lang.Package class, which uses the class loader to provide you with information about your classes.

Example:

 String.class.getPackage().getImplementationVersion(); Package.getPackage(this).getImplementationVersion(); Package.getPackage("java.lang.String").getImplementationVersion(); 

I think that the logback function is known to use this function to track the name / version of the JAR of each class in its created stacktraces.

see also http://docs.oracle.com/javase/8/docs/technotes/guides/versioning/spec/versioning2.html#wp90779

+5
Jan 18 '17 at 17:07 on
source share

This simple program lists all cases for the jar version, namely

  • Version found in manifest file
  • There is no version in the manifest, and even with the name jar
  • Manifest file not found

     Map<String, String> jarsWithVersionFound = new LinkedHashMap<String, String>(); List<String> jarsWithNoManifest = new LinkedList<String>(); List<String> jarsWithNoVersionFound = new LinkedList<String>(); //loop through the files in lib folder //pick a jar one by one and getVersion() //print in console..save to file(?)..maybe later File[] files = new File("path_to_jar_folder").listFiles(); for(File file : files) { String fileName = file.getName(); try { String jarVersion = new Jar(file).getVersion(); if(jarVersion == null) jarsWithNoVersionFound.add(fileName); else jarsWithVersionFound.put(fileName, jarVersion); } catch(Exception ex) { jarsWithNoManifest.add(fileName); } } System.out.println("******* JARs with versions found *******"); for(Entry<String, String> jarName : jarsWithVersionFound.entrySet()) System.out.println(jarName.getKey() + " : " + jarName.getValue()); System.out.println("\n \n ******* JARs with no versions found *******"); for(String jarName : jarsWithNoVersionFound) System.out.println(jarName); System.out.println("\n \n ******* JARs with no manifest found *******"); for(String jarName : jarsWithNoManifest) System.out.println(jarName); 

It uses the javaxt-core jar, which can be downloaded from http://www.javaxt.com/downloads/

+3
Dec 10 '15 at 10:20
source share

I'm late, but you can try the following two methods

using these necessary classes

 import java.util.jar.Attributes; import java.util.jar.Manifest; 

These methods allow me to access the jar attributes. I like to be backward compatible and use the latter. So i used this

 public Attributes detectClassBuildInfoAttributes(Class sourceClass) throws MalformedURLException, IOException { String className = sourceClass.getSimpleName() + ".class"; String classPath = sourceClass.getResource(className).toString(); if (!classPath.startsWith("jar")) { // Class not from JAR return null; } String manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1) + "/META-INF/MANIFEST.MF"; Manifest manifest = new Manifest(new URL(manifestPath).openStream()); return manifest.getEntries().get("Build-Info"); } public String retrieveClassInfoAttribute(Class sourceClass, String attributeName) throws MalformedURLException, IOException { Attributes version_attr = detectClassBuildInfoAttributes(sourceClass); String attribute = version_attr.getValue(attributeName); return attribute; } 

This works well when you use maven and you need detailed pom details for famous classes. Hope this helps.

+2
Oct 19 '17 at 13:54 on
source share

You can filter the version from the MANIFEST file using

unzip -p my.jar META-INF/MANIFEST.MF | grep 'Bundle-Version'

0
Oct 03 '18 at 21:50
source share

It can be checked using the java -jar jarname

-13
May 22 '15 at 7:26
source share



All Articles