Java Jar Manifest getManifestAttributes(File jarFile)

Here you can find the source of getManifestAttributes(File jarFile)

Description

get Manifest Attributes

License

Open Source License

Declaration

public static Hashtable<String, String> getManifestAttributes(File jarFile) 

Method Source Code


//package com.java2s;
/*---------------------------------------------------------------
*  Copyright 2011 by the Radiological Society of North America
*
*  This source software is released under the terms of the
*  RSNA Public License (http://mirc.rsna.org/rsnapubliclicense)
*----------------------------------------------------------------*/

import java.io.*;

import java.util.*;
import java.util.jar.*;

public class Main {
    public static Hashtable<String, String> getManifestAttributes(String path) {
        return getManifestAttributes(new File(path));
    }/*from w  w  w  .jav a2s. c  om*/

    public static Hashtable<String, String> getManifestAttributes(File jarFile) {
        Hashtable<String, String> h = new Hashtable<String, String>();
        JarFile jar = null;
        try {
            jar = new JarFile(jarFile);
            Manifest manifest = jar.getManifest();
            h = getManifestAttributes(manifest);
        } catch (Exception ex) {
            h = null;
        }
        if (jar != null) {
            try {
                jar.close();
            } catch (Exception ignore) {
            }
        }
        return h;
    }

    public static Hashtable<String, String> getManifestAttributes(Manifest manifest) {
        Hashtable<String, String> h = new Hashtable<String, String>();
        try {
            Attributes attrs = manifest.getMainAttributes();
            Iterator it = attrs.keySet().iterator();
            while (it.hasNext()) {
                String key = it.next().toString();
                h.put(key, attrs.getValue(key));
            }
        } catch (Exception ignore) {
        }
        return h;
    }
}

Related

  1. getManifest(ZipFile zip)
  2. getManifest(ZipFile zipFile)
  3. getManifestAttribute(InputStream in, String attr)
  4. getManifestAttribute(Manifest m)
  5. getManifestAttribute(String jarUrl, String attribute)
  6. getManifestEntryValue(IResource manifest, String entryKey)
  7. getManifestFileLocation(String moduleDir)
  8. getManifestHeaders(File aJarFile)
  9. getManifestHeaders(Manifest manifest)