Java Jar Manifest getManifest(final String jarFileName)

Here you can find the source of getManifest(final String jarFileName)

Description

Gets the manifest object from jar file.

License

Apache License

Parameter

Parameter Description
jarFileName the jar file name

Exception

Parameter Description
IOException I/O Exception

Return

the manifest object

Declaration

public static Manifest getManifest(final String jarFileName) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.*;

import java.util.jar.Manifest;
import java.util.jar.JarFile;
import java.util.zip.ZipEntry;

public class Main {
    /**//from  w  w w  .j av a 2  s. c  om
     * Gets the manifest object from jar file.
     *
     * @param jarFileName the jar file name
     * @return the manifest object
     * @throws IOException I/O Exception
     */
    public static Manifest getManifest(final String jarFileName) throws IOException {
        final JarFile jarFile = new JarFile(jarFileName);

        final Manifest manifest = getManifest(jarFile);

        jarFile.close();

        return manifest;
    }

    /**
     * Gets the manifest object from jar file.
     *
     * @param jarFile the jar file
     * @return the manifest object
     * @throws IOException I/O Exception
     */
    public static Manifest getManifest(final JarFile jarFile) throws IOException {
        Manifest manifest = null;

        ZipEntry zipEntry = jarFile.getEntry("META-INF/MANIFEST.MF");

        if (zipEntry == null) {
            zipEntry = jarFile.getEntry("meta-inf/manifest.mf");
        }

        if (zipEntry != null) {
            final InputStream is = jarFile.getInputStream(zipEntry);

            manifest = new Manifest(is);

            is.close();
        }

        return manifest;
    }
}

Related

  1. getManifest()
  2. getManifest(File file)
  3. getManifest(File in)
  4. getManifest(File jarFile)
  5. getManifest(File pluginFile)
  6. getManifest(JarFile pluginJarFile)
  7. getManifest(String className)
  8. getManifest(String path)
  9. getManifest(ZipFile zip)