I am currently working on a J2ME polish application, just enhancing it. I am finding difficulties to get the exact version of the jar file. Is there any way to find the version of the jar file for the imports done in the class? I mean if you have some thing, import x.y.z; can we know the version of the jar x.y package belongs to?
17 Answers
Decompress the JAR file and look for the manifest file (META-INF\MANIFEST.MF
). The manifest file of JAR file might contain a version number (but not always a version is specified).

- 55,411
- 20
- 125
- 222

- 4,526
- 17
- 56
- 69
-
As i told that I am working on enhancing the application, I have downloaded the jar files and I know the version of the jar files. But I wanted to know the version of the jar which the package belongs to, I hope you get it. – Ritesh Mengji Apr 29 '11 at 16:52
-
1To explain you more, I have import x.y.z, I know that x.y belongs to a-4.1.jar, but the application which i am working has been developed long back, and I dono what version of a.jar file have they used, I am worried about the version because, some of the classes have been depreciated from the jar of the older version (I feel so), because, even though I have jar in the library, I find the import cannot be resolved – Ritesh Mengji Apr 29 '11 at 16:54
-
So is it that, if you know the version of jar which they used while building the application, you would also use the same version of jar to execute the application? – Vivek Apr 29 '11 at 17:21
-
1If that is what your requirement is, then am afraid that you will have to rebuild the application with exclusion of deprecated jars. Because finding version number associated with a given jar is like one to one function. Only one version number for one jar file. But finding which version of jar was used at the time of development of application sounds highly impossible to me unless the developer attaches the required jars with the application. – Vivek Apr 29 '11 at 17:26
-
The problem is I dono what version they used, SO i guess I need to work out using every version of the jar file... lets see if I can find any solution. – Ritesh Mengji Apr 29 '11 at 17:46
-
Ya, that is what u can do. U need to check with different versions of jar files and wait till you get lucky. :) – Vivek Apr 29 '11 at 17:52
-
This answer (and others) is currently [discussed on Meta](http://meta.stackoverflow.com/questions/305645/do-we-want-single-complete-answers) – Thomas Weller Sep 09 '15 at 09:58
-
2Recording version in MANIFEST.MF appears to be optional. There's no version recorded in various `sqljdbc42.jar` files that I've used with Cognos, yet Cognos is able to report a version (4.2.6420.100). Where is it getting this version from if it's not recorded in the manifest? – Nick.Mc Jan 09 '20 at 07:09
-
Thank you! This is working for me: `unzip -p /usr/share/jenkins/agent.jar META-INF/MANIFEST.MF | awk '$1 == "Version:"{print $2}' | sed 's/\r//'` – nroose Jun 02 '20 at 21:41
You need to unzip it and check its META-INF/MANIFEST.MF
file, e.g.
unzip -p file.jar | head
or more specific:
unzip -p file.jar META-INF/MANIFEST.MF

- 155,785
- 88
- 678
- 743
Just to expand on the answers above, inside the META-INF/MANIFEST.MF file in the JAR, you will likely see a line: Manifest-Version: 1.0
← This is NOT the jar versions number!
You need to look for Implementation-Version
which, if present, is a free-text string so entirely up to the JAR's author as to what you'll find in there.
See also Oracle docs and Package Version specificaion

- 1,692
- 1
- 14
- 6
-
This answer (and others) is currently [discussed on Meta](http://meta.stackoverflow.com/questions/305645/do-we-want-single-complete-answers) – Thomas Weller Sep 09 '15 at 09:59
Just to complete the above answer.
Manifest file is located inside jar at META-INF\MANIFEST.MF
path.
You can examine jar's contents in any archiver that supports zip.

- 14,023
- 6
- 43
- 67

- 24,954
- 11
- 143
- 151
-
2This answer (and others) is currently [discussed on Meta](http://meta.stackoverflow.com/questions/305645/do-we-want-single-complete-answers) – Thomas Weller Sep 09 '15 at 09:58
Each jar version has a unique checksum. You can calculate the checksum for you jar (that had no version info) and compare it with the different versions of the jar. We can also search a jar using checksum.
Refer this Question to calculate checksum: What is the best way to calculate a checksum for a file that is on my machine?
-
5I just calculated the jar md5 and pasted it to google. Worked great, thanks a lot! – mik01aj Nov 07 '14 at 12:09
Basically you should use the java.lang.Package
class which use the classloader to give you informations about your classes.
example:
String.class.getPackage().getImplementationVersion();
Package.getPackage(this).getImplementationVersion();
Package.getPackage("java.lang.String").getImplementationVersion();
I think logback is known to use this feature to trace the JAR name/version of each class in its produced stacktraces.
see also http://docs.oracle.com/javase/8/docs/technotes/guides/versioning/spec/versioning2.html#wp90779

- 3,486
- 3
- 32
- 38
Thought I would give a more recent answer as this question still comes up pretty high on searches.
Checking CLi JAR Version:
Run the following on the CLi jar file:
unzip -p jenkins-cli.jar META-INF/MANIFEST.MF
Example Output:
Manifest-Version: 1.0
Built-By: kohsuke
Jenkins-CLI-Version: 2.210 <--- Jenkins CLI Version
Created-By: Apache Maven 3.6.1
Build-Jdk: 1.8.0_144
Main-Class: hudson.cli.CLI
The CLi version is listed above.
To get the Server Version, run the following:
java -jar ./jenkins-cli.jar -s https://<Server_URL> -auth <email>@<domain>.com:<API Token> version
(the above will vary based on your implementation of authentication, please change accordingly)
Example Output:
Dec 23, 2019 4:42:55 PM org.apache.sshd.common.util.security.AbstractSecurityProviderRegistrar getOrCreateProvider
INFO: getOrCreateProvider(EdDSA) created instance of net.i2p.crypto.eddsa.EdDSASecurityProvider
2.210 <-- Jenkins Server Version

- 830
- 1
- 8
- 18
This simple program will list all the cases for version of jar namely
- Version found in Manifest file
- No version found in Manifest and even from jar name
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/

- 250
- 2
- 14
-
Thanks for the reference to javaxt, I just used the simpler code sample there from http://www.javaxt.com/Tutorials/Jar/How_to_Get_the_Version_Number_of_a_JAR_File – David May 11 '16 at 03:34
-
1FYI, for those who prefer maven to pull javaxt-core rather than downloading the JAR, you could do either of these approaches: https://gist.github.com/daluu/dda7b29cb5b6e0fbfbaec664eb759739, https://gist.github.com/daluu/52af7eef52563ddf78fe – David May 11 '16 at 03:37
I'm late this but you can try the following two methods
using these needed classes
import java.util.jar.Attributes;
import java.util.jar.Manifest;
These methods let me access the jar attributes. I like being backwards compatible and use the latest. 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 are using maven and need pom details for known classes. Hope this helps.

- 448
- 5
- 12
For Linux, try following:
find . -name "YOUR_JAR_FILE.jar" -exec zipgrep "Implementation-Version:" '{}' \;|awk -F ': ' '{print $2}'

- 1,498
- 1
- 11
- 10
-
1`zipgrep "Implementation-Version:" JAVA.jar | awk -F ': ' '{print $2}'` – Ivan Chau Mar 11 '22 at 03:54
You can filter version from the MANIFEST file using
unzip -p my.jar META-INF/MANIFEST.MF | grep 'Bundle-Version'

- 57
- 6
-
This seems to mostly duplicate this older answer - https://stackoverflow.com/a/38313502/272387 - and manifests are not guaranteed to have `Bundle-Version`. – Richlv Jul 26 '19 at 07:00
best solution that does not involve extracting the jar files is to run the following command. If the jar file does not contain a manifest file you will get a "WARNING: Manifest file not found"
java -jar file.jar -v

- 11
- 3
You could execute this script, it will find all versions of jar files in a directory:
find /directory -maxdepth 3 -name "*.jar" | xargs -l % sh -c "JAR=\"\$(basename % .jar)"; VERSION=\"\$(unzip -q -c % META-INF/MANIFEST.MF | grep 'Implementation-Version' cut -d' ' -f2)\"; echo \"\$JAR \$VERSION\";" | sort

- 516
- 4
- 6
[A] Manually we can extract/unzip the jar file and check Bundle-Version or Implementation-Version keyword in META-INF/MANIFEST.MF file.
[B] In Unix environment , you can easily use the grep command in combination with unzip and then cut command to get the version. [This soluction does assume that there will be version mentioned in META-INF/MANIFEST.MF . (80% chances)]
Run below command to get the VERSION.
VERSION=unzip -p "javaPackage.jar" "META-INF/MANIFEST.MF" | grep -m1 -E "Bundle-Version|Implementation-Version:" | cut -d':' -f2 | awk '{$1=$1;print}' 2>/dev/null
;
Explanation :
- unzip -> Get content of META-INF/MANIFEST.MF file from your java jar, This can be done without extracting the jar.
- grep -> Search matching word against either "Bundle-Version" or "Implementation-Version:" keyword
- cut -> Split based on hyphen and get 2nd part
- awk -> Trim space present around the jar-version
- 2>/dev/null -> Error redirection to /dev/null
Note : - If you want to find version of multiple jars , then run a for loop and call above script.

- 93
- 1
- 10
Just rename the extension with .zip instead of .jar. Then go to META-INF/MANIFEST.MF and open the MANIFEST.MF file with notepad. You can find the implementation version there.

- 17
- 3