views:

244

answers:

6

I'm able to read the Manifest file inside of my Java code, but I would also like to know if it's possible, and if it is, how to open up a JAR file from the command line and view its Manifest.MF file, or at the very least be able to specify a property of the Manifest.MF file and view it's value.

+1  A: 

the jar executable provided by JDK works the same way tar works on linux.

jar xvf for example .... See jar options.

Manuel Selva
+5  A: 

From here:

You can extract selected entries from a jar file. For instance, if you only want to view the meta-inf/manifest.mf file, you can

C:\Sun\AppServer\lib>jar xvf j2ee.jar META-INF/MANIFEST.MF
inflated: META-INF/MANIFEST.MF

Or using a backslash instead of a forward slash:

C:\Sun\AppServer\lib>jar xvf j2ee.jar META-INF\MANIFEST.MF
inflated: META-INF/MANIFEST.MF

The entry names are case sensitive, and so the following will not extract anything:

 C:\Sun\AppServer\lib>jar xvf j2ee.jar meta-inf/manifest.mf

Of course, you can always double-click the entry to view it in WinZip, fileroller, or other tools.

VonC
i'm guessing he needs it programatically, so your first bit would be most appropriate.
geowa4
+2  A: 

Something like this should work:

jar -xf <jarfile.jar> META-INF/MANIFEST.MF
Jack Leow
+1  A: 

Properties for runtime should not be defined in the manifest, they should be defined in separated config files that follow the Java Properties style. Assuming you are checking the manifest at runtime for whatever reason.

But if you need to:

jar xvf somejar.jar META-INF/MANIFEST.MF

will inflate the manifest for your viewing pleasure.

geowa4
+1  A: 

There is not a way with the jar command; the closest you can get is to use -tf to show the presence or absence of a META-INF/MANIFEST.MF file or -xf to extract it.

Work-arounds:

  • You could write your own class to do this
  • You could use any ZIP file viewer to extract the contents - many will write the contents of a file in an archive to stdout so that it can be piped into another command (remember, jar files are just a specific usage of zip files)
lavinio
A: 

it looks like the unzip command will help you -- it's available on most Un*x variants and is part of cygwin as well, if you are on Windows. unzip -qc *jar-file* META-INF/MANIFEST.MF will dump the contents of the manifest to the console.

smoothreggae