Create a Manifest for a JAR File in Java

Description

The following code shows how to create a Manifest for a JAR File.

Example


//from   w ww.jav a  2 s  .  c  o m
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);
  }
}




















Home »
  Java Tutorial »
    I/O »




Binary File
Byte Array
CharSet
Checksum
Console
Create Copy Move Delete
Directory
Drive
Encode Decode
File Attribute
File Lock
File System
GZIP
Jar File
NIO Buffer
Path
Scanner
StreamTokenizer
Temporary File
Text File
Zip