Thomas Owens
Thomas Owens

Reputation: 116187

Using tools that the JDK and/or JRE provide, is there a way to view the Manifest file for a given JAR?

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.

Upvotes: 4

Views: 1740

Answers (7)

pharsfalvi
pharsfalvi

Reputation: 807

You can just use vi for that. If you want to make sure that you don't change the file, open with with -R switch (for readonly). e.g:

vi -R sample-1.0.0-SNAPSHOT.jar

You can navigate to the zip file with the up/down arrow, or search with / e.g.:

/MANIFEST.MF

To exit type the following sequence

:q <Enter>

Upvotes: 0

smooth reggae
smooth reggae

Reputation: 2219

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.

Upvotes: 2

lavinio
lavinio

Reputation: 24309

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)

Upvotes: 1

geowa4
geowa4

Reputation: 41833

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.

Upvotes: 1

Jack Leow
Jack Leow

Reputation: 22487

Something like this should work:

jar -xf <jarfile.jar> META-INF/MANIFEST.MF

Upvotes: 2

VonC
VonC

Reputation: 1326676

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.

Upvotes: 5

Manuel Selva
Manuel Selva

Reputation: 19060

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

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

Upvotes: 1

Related Questions