Java Jar Manifest getManifestProperty(ClassLoader clContainingManifest, String manifestKey)

Here you can find the source of getManifestProperty(ClassLoader clContainingManifest, String manifestKey)

Description

get Manifest Property

License

Open Source License

Declaration

public static String getManifestProperty(ClassLoader clContainingManifest, String manifestKey)
            throws IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.IOException;
import java.io.InputStream;

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

import java.util.zip.ZipEntry;

public class Main {
    public static String getManifestProperty(String jarFilename, String manifestKey) throws IOException {
        try (JarFile file = new JarFile(jarFilename)) {
            ZipEntry entry = file.getEntry("META-INF/MANIFEST.MF");
            InputStream is = file.getInputStream(entry);
            if (is == null) {
                return "(No META-INF/MANIFEST.MF file)";
            }/* ww w  .  j  a v a2 s. co  m*/
            return readManifestProperty(is, manifestKey);
        }
    }

    public static String getManifestProperty(ClassLoader clContainingManifest, String manifestKey)
            throws IOException {
        // Check Manifest file for generated build number
        InputStream is = clContainingManifest.getResourceAsStream("META-INF/MANIFEST.MF");
        return readManifestProperty(is, manifestKey);
    }

    private static String readManifestProperty(InputStream is, String manifestKey) throws IOException {
        Manifest mf = new Manifest();
        if (is == null) {
            return "(No META-INF/MANIFEST.MF file)";
        }
        mf.read(is);
        return mf.getMainAttributes().getValue(manifestKey);
    }
}

Related

  1. getManifestFileLocation(String moduleDir)
  2. getManifestHeaders(File aJarFile)
  3. getManifestHeaders(Manifest manifest)
  4. getManifestHeaderValues(final Manifest manifest, final String headerName)
  5. getManifestPath(String moduleDir)
  6. getManifestProperty(File file, String name)
  7. getManifestProperty(Manifest manifest, String propertyName)
  8. getManifestValue(File jarFile, String key)
  9. getManifestValue(JarFile jarFile, String key, String defaultValue)