How can I add Attributes to the MainAttributes section of a Manifest object, then write the Manifest to a JarFile using JarOutputStream?

Garth Somerville

To add main attributes to an existing manifest object, use the read() method of Manifest like so:

manifest.read( new StringBufferInputStream( "MainAttribute1: value1 MainAttribute2: value2 " ) );

This will leave all existing attributes unchanged in the manifest, and simply add the ones you specify.

To write the manifest to the Jar file using JarOutputStream, just use the constructor for JarOutputStream that takes a Manifest as the second argument.