This post demonstrates how to read the Jar file manifest.
Java Codes
For our purpose, we use java.util.JarFile
which is readily available Java. This means that we do not need 3rd-party libraries.
[wp_ad_camp_2]
In the following codes, we read tools.jar and print its manifest.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | package com.turreta.java.jar; import java.io.File; import java.io.IOException; import java.util.jar.JarFile; public class JarDemo { public static void main(String[] args) { try (JarFile jf = new JarFile(new File("C:/Program Files/Java/jdk1.8.0_101/lib/tools.jar"))) { System.out.println(String.format("comment: %s", jf.getComment())); System.out.println(String.format("name: %s", jf.getName())); jf.getManifest().getMainAttributes().forEach((k, v) -> System.out.println(String.format("%s = %s", k, v)) ); } catch (IOException e) { // Do something } } } |
Output
1 2 3 4 | comment: PACK200 name: C:\Program Files\Java\jdk1.8.0_101\lib\tools.jar Created-By = 1.7.0_07 (Oracle Corporation) Manifest-Version = 1.0 |
[wp_ad_camp_1]
References