This week's book giveaway is in the Java in General forum.
We're giving away four copies of Helidon Revealed: A Practical Guide to Oracle’s Microservices Framework and have Michael Redlich on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Obtaining Manifest from Jar

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 !
 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
After some pecan pie, you might want to cleanse your palatte with this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic