File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Obtaining Manifest from Jar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Obtaining Manifest from Jar" Watch "Obtaining Manifest from Jar" New topic

Obtaining Manifest from Jar

Doug Melzer
Ranch Hand

Joined: Mar 23, 2000
Posts: 51
I'd like to obtain a version number from a .jar file's manifest, but I'd like to do so without having to know the file location of the .jar file.
Is it possible, given a class that was loaded from the .jar file, to obtain a handle to that .jar file's manifest?
Thomas Smets
Ranch Hand

Joined: Dec 11, 2001
Posts: 111
I believe you will have to work out the jars to find from which file it comes from !
This means that you will have to find all the JAR's in you classpath & find in them where you class source is located ! From there you could search for the MANIFEST file in the current jar !
This could be handy !
Sun's tutorial on how to read Jar from Java !

Thomas Smets
Just another developper
Steve Deadsea
Ranch Hand

Joined: Dec 03, 2001
Posts: 125
There may well be a way to do it without knowing the name of the jar file. It works for other files in the jar file (but note I haven't tried it with anything in the META-INF directory)
The basic idea is that everything that is in the jar file is in the classpath, and you get a InputStream to a system resource from the classloader. Here is how it might work.
Doug Melzer
Ranch Hand

Joined: Mar 23, 2000
Posts: 51
I've tried a couple of these ideas, but the problem that I encounter is that if there are multiple .jar files on the classpath that I can't ensure I'm reading the desired manifest file.
Thanks for the suggestions!
I agree. Here's the link:
subject: Obtaining Manifest from Jar
It's not a secret anymore!