Mega Code Archive

 
Categories / Java / File Input Output
 

Creating a Manifest for a JAR File

import java.io.ByteArrayInputStream; import java.io.FileInputStream; import java.io.InputStream; import java.util.jar.Manifest; public class Main {   public static void main(String[] argv) throws Exception {     // Create a manifest from a file     InputStream fis = new FileInputStream("manifestfile");     Manifest manifest = new Manifest(fis);     // Construct a string version of a manifest     StringBuffer sbuf = new StringBuffer();     sbuf.append("Manifest-Version: 1.0\n");     sbuf.append("\n");     sbuf.append("Name: javax/swing/JScrollPane.class\n");     sbuf.append("Java-Bean: True\n");     // Convert the string to a input stream     InputStream is = new ByteArrayInputStream(sbuf.toString().getBytes("UTF-8"));     // Create the manifest     manifest = new Manifest(is);   } }