pillingworth
pillingworth

Reputation: 3238

Manifest.mf file viewer?

Are there any tools available which will take a manifest.mf file from a jar and display the contents nicely?

In particular when working with OSGi bundles the Export-Package and Import-Package entries can get quite large and difficult to quite work out what is going on. Added to this simple keyword text searching is not 100% reliable because of line breaks.

Upvotes: 7

Views: 5814

Answers (8)

Azurespot
Azurespot

Reputation: 3152

I opened my jar in 7-Zip (any unzipper/unarchiver will do), then you have the option to copy the MANIFEST.MF file elsewhere in your computer. I copied it to my desktop, then opened with Visual Studio Code. Any text editor would have worked.

Alternatively, I opened the jar with Atom. It showed the entire tree structure of my jar. I double-clicked the MANIFEST.MF file and it opened right up in Atom.

Upvotes: 0

Morten Jensen
Morten Jensen

Reputation: 46

Here is an online pretty printer of manifests; https://apinx.dk/javamanifest/

You can drag'n'drop the .jar file or copy-paste the manifest.mf itself.

Upvotes: 3

robinst
robinst

Reputation: 31427

Here's an online pretty-printer for manifest files, with optional sorting:

https://robinst.github.io/jar-manifest-formatter/

Upvotes: 3

Adrien
Adrien

Reputation: 1105

Parse it in javascript ;) Here's a JSFiddle to pretty-print an OSGi MANIFEST.MF file:

http://jsfiddle.net/scotch/5WJwd/embedded/result/

var sectionsText = text.split(/\n\n\n/),
    sections = {},
    sectionText,
    name,
    body,
    packagesText,
    packages,
    packageName,
    packageBody;

for (var i in sectionsText) {
    sectionText = sectionsText[i];
    name = sectionText.substr(0, sectionText.indexOf(": "));
    body = sectionText.substr(sectionText.indexOf(": ") + 2);
    sections[name] = body;

    if (name.indexOf("Package") != -1) {
        body = body.replace(/[\n\r] /g, '');
        body = body.replace(/(,)(?=(?:[^"]|"[^"]*")*$)/g, "$1\n");
        packagesText = body.split(/\n/);
        packages = {};
        for (var i in packagesText) {
            packageBody = packagesText[i];
            packageName = packageBody.substr(0, packageBody.indexOf(";"));
            packageBody = packageBody.substr(packageBody.indexOf(";")+1);

            if (collapse) {
                packageBody = packageBody.replace(/uses:="[^"]*"/g, 'uses:="..."');
            }

            packages[packageName] = packageBody;//.replace(/;/g, ';\n');
        }
        sections[name] = packages;
    }
}

It sorts entries by alphabetical order too, so you can compare them. Hope it will be useful for someone (especially people developing outside of Eclipse).

Upvotes: 2

Peter Kriens
Peter Kriens

Reputation: 15372

bnd itself can be run from the command line and will print all details:

 java -jar biz.aQute.bnd.run.jar xx.jar

You can also click on a jar in bndtools and select the print tab, this gives you more details than you probably need.

bnd can be download from https://bndtools.ci.cloudbees.com/job/bnd.master/lastSuccessfulBuild/artifact/dist/bundles/biz.aQute.bnd/biz.aQute.bnd-latest.jar

Type bnd help for information about the commands.

Upvotes: 2

Max Spring
Max Spring

Reputation: 1140

I downloaded the bnd.jar from Maven Central.
http://repo1.maven.org/maven2/biz/aQute/bnd/bnd/2.2.0/bnd-2.2.0.jar

And yes, I can run it and it pretty-prints the manifest:

java -jar bnd-2.2.0.jar example.jar

The print command shows Import-Package and Export-Package even nicer:

java -jar bnd-2.2.0.jar print example.jar

Upvotes: 3

Robin
Robin

Reputation: 24272

I believe the eclipse plugin for BND tools does it fairly nicely. It has an editor for viewing a jar file.

Upvotes: 5

shyam
shyam

Reputation: 9368

If you are using eclipse you can use the Plugin Manifest Editor configured by

enter image description here

Upvotes: 0

Related Questions