Java Jar Manifest getManifest()

Here you can find the source of getManifest()

Description

get Manifest

License

Open Source License

Declaration

public static Manifest getManifest() 

Method Source Code


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

import java.util.jar.Manifest;
import java.util.jar.Attributes;
import java.util.Map;

public class Main {
    public static Manifest getManifest() {
        Manifest manifest = new Manifest();

        /* Add main attributes
         1. Manifest Version//www .ja v  a  2s. c o  m
         2. Main-Class
         3. Sealed
        */
        Attributes mainAttribs = manifest.getMainAttributes();
        mainAttribs.put(Attributes.Name.MANIFEST_VERSION, "1.0");
        mainAttribs.put(Attributes.Name.MAIN_CLASS, "com.jdojo.archives.Test");
        mainAttribs.put(Attributes.Name.SEALED, "true");

        /* Add two individual sections */
        /* Do not seal the com/jdojo/archives/ package. Note that you 
           have sealed the whole JAR file and to exclude this package 
           you we must add a Sealed: false attribute for this package 
           separately. 
        */
        Map<String, Attributes> attribsMap = manifest.getEntries();

        // Create an attribute "Sealed : false" and 
        // add it for individual entry "Name: com/jdojo/archives/"
        Attributes a1 = getAttribute("Sealed", "false");
        attribsMap.put("com/jdojo/archives/", a1);

        // Create an attribute "Content-Type: image/bmp" and 
        // add it for images/logo.bmp
        Attributes a2 = getAttribute("Content-Type", "image/bmp");
        attribsMap.put("images/logo.bmp", a2);

        return manifest;
    }

    public static Attributes getAttribute(String name, String value) {
        Attributes a = new Attributes();
        Attributes.Name attribName = new Attributes.Name(name);
        a.put(attribName, value);
        return a;
    }
}

Related

  1. getAttribute(String attributeName, Manifest manifest)
  2. getBundleClassPath(Manifest manifest)
  3. getBundleVersion(Manifest manifest)
  4. getHeader(String name, Manifest manifest)
  5. getMainAttributeValue(Manifest manifest, String attribute)
  6. getManifest()
  7. getManifest(File file)
  8. getManifest(File in)
  9. getManifest(File jarFile)