Java Jar Manifest getManifestValue(File jarFile, String key)

Here you can find the source of getManifestValue(File jarFile, String key)

Description

Gets main attribute value from jar manifest

License

LGPL

Parameter

Parameter Description
jarFile jar file
key name of attribute we are looking for

Exception

Parameter Description
IOException an exception

Return

value of the attribute, null if not found

Declaration

public static String getManifestValue(File jarFile, String key) throws IOException 

Method Source Code


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

import java.io.File;
import java.io.IOException;
import java.util.jar.Attributes;
import java.util.jar.JarFile;
import java.util.jar.Manifest;

public class Main {
    /**// ww w . j a va2  s  .  c om
     * Gets main attribute value from jar manifest 
     * 
     * @param jarFile
     *          jar file
     * @param key
     *          name of attribute we are looking for
     * @return
     *          value of the attribute, null if not found
     * @throws IOException
     */
    public static String getManifestValue(File jarFile, String key) throws IOException {
        JarFile jF = null;
        try {
            jF = new JarFile(jarFile);
            Manifest mf = jF.getManifest();
            return mf.getMainAttributes().getValue(key);
        } finally {
            if (jF != null) {
                jF.close();
            }
        }
    }

    /**
     * Gets all main attributes of jar manifest
     * 
     * @param jarFile
     * @return
     * @throws IOException
     */
    private static Attributes getMainAttributes(File jarFile) throws IOException {
        JarFile jF = null;
        try {
            jF = new JarFile(jarFile);
            Manifest mf = jF.getManifest();
            return mf.getMainAttributes();
        } finally {
            if (jF != null) {
                jF.close();
            }
        }
    }
}

Related

  1. getManifestHeaderValues(final Manifest manifest, final String headerName)
  2. getManifestPath(String moduleDir)
  3. getManifestProperty(ClassLoader clContainingManifest, String manifestKey)
  4. getManifestProperty(File file, String name)
  5. getManifestProperty(Manifest manifest, String propertyName)
  6. getManifestValue(JarFile jarFile, String key, String defaultValue)
  7. getManifestVersionNumber(File file)
  8. getValueFromAttr(Attributes attributes, String manifestValue)
  9. isOSGiManifest(Manifest manifest)