Java Utililty Methods Jar Manifest

List of utility methods to do Jar Manifest

Description

The list of methods to do Jar Manifest are organized into topic(s).

Method

ManifestgetManifest(final String jarFileName)
Gets the manifest object from jar file.
final JarFile jarFile = new JarFile(jarFileName);
final Manifest manifest = getManifest(jarFile);
jarFile.close();
return manifest;
ManifestgetManifest(JarFile pluginJarFile)
get Manifest
try {
    return pluginJarFile.getManifest();
} catch (IOException ex) {
    return null;
ManifestgetManifest(String className)
Return a Manifest which indicate the parameter as the class containing the main of the application.
Manifest mf = new Manifest();
mf.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
mf.getMainAttributes().put(new Attributes.Name("Built-By"), "Sonet Nicolas");
mf.getMainAttributes().put(new Attributes.Name("Created-By"), "Sonet Nicolas");
mf.getMainAttributes().put(Attributes.Name.MAIN_CLASS, className);
return mf;
ManifestgetManifest(String path)
get Manifest
File jar = new File(path);
JarFile jf = new JarFile(new File(path));
Manifest mf = new JarFile(jar).getManifest();
jf.close();
return mf;
ManifestgetManifest(ZipFile zip)
Use this utility to read Manifest from a JarFile or ZipFile due to http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6735255
ZipEntry entry = zip.getEntry("META-INF/MANIFEST.MF");
if (entry == null)
    return null;
InputStream in = zip.getInputStream(entry);
try {
    return new Manifest(in);
} finally {
    in.close();
...
ManifestgetManifest(ZipFile zipFile)
get Manifest
ZipEntry manifestEntry = zipFile.getEntry(MANIFEST);
return new Manifest(zipFile.getInputStream(manifestEntry));
StringgetManifestAttribute(InputStream in, String attr)
get Manifest Attribute
try {
    Manifest manifest = new Manifest(in);
    Attributes attributes = manifest.getMainAttributes();
    return attributes.getValue(attr);
} catch (IOException ex) {
    throw new UncheckedIOException(ex);
StringgetManifestAttribute(Manifest m)
get Manifest Attribute
String value = null;
if (m != null) {
    value = m.getMainAttributes().getValue("Cytoscape-Plugin");
return value;
StringgetManifestAttribute(String jarUrl, String attribute)
Get an attribute value
JarFile jar = new JarFile(jarUrl);
Attributes attr = jar.getManifest().getMainAttributes();
String value = attr.getValue(attribute);
jar.close();
return value;
HashtablegetManifestAttributes(File jarFile)
get Manifest Attributes
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;
...