![]() |
The Java Developers Almanac 1.4 |
|
e382. Creating a Manifest for a JAR FileA manifest for a JAR file can only be created from an input stream. This example creates a manifest from a file and from a constructed string. The format of a manifest is described in:http://java.sun.com/products/jdk/1.2/docs/guide/jar/manifest.html try {
// 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);
} catch (IOException e) {
}
Here's an example of a manifest file:
Manifest-Version: 1.0
Specification-Title: Java Platform API Specification
Specification-Version: 1.4
Implementation-Title: Java Runtime Environment
Implementation-Version: 1.4.0-rc
Created-By: 1.4.0-rc (Sun Microsystems Inc.)
Implementation-Vendor: Sun Microsystems, Inc.
Specification-Vendor: Sun Microsystems, Inc.
Name: javax/swing/JScrollPane.class
Java-Bean: True
Name: javax/swing/JCheckBoxMenuItem.class
Java-Bean: True
Name: javax/swing/JTabbedPane.class
Java-Bean: True
Name: javax/swing/JMenuItem.class
Java-Bean: True
Name: javax/swing/JTable.class
Java-Bean: True
e381. Listing the Main Attributes in a JAR File Manifest e383. Writing a JAR File Manifest to a File e384. Creating and Signing a JAR File Using jarsigner © 2002 Addison-Wesley. |