views:

164

answers:

2

I have an Eclipse plugin for which I create the OSGi bundle JARs with Ant. I would like to sign them with the Ant task, but that overwrites the MANIFEST.MF contents with the class signatures, making the OSGi bundles unusable. The JDK jarsigner tool has the same behavior. The Eclipse PDE seems to have that functionality, but as far as I know you can only use it from within Eclipse. I want to be able to run my Ant build from the command line. Does anybody know of a simple way to append the class signatures to MANIFEST.MF instead of overwriting it?

A: 

I don't think the manifest is overwritten by default. Observe the following console script:

$ touch MyMainClass.class

$ echo 'Main-Class: MyMainClass' > MyManifest

$ jar cvmf MyManifest myjar.jar MyMainClass.class
added manifest
adding: MyMainClass.class(in = 0) (out= 0)(stored 0%)

$ unzip -c myjar.jar META-INF/MANIFEST.MF
Archive:  myjar.jar
  inflating: META-INF/MANIFEST.MF
Manifest-Version: 1.0
Created-By: 1.6.0_17 (Apple Inc.)
Main-Class: MyMainClass

$ jarsigner myjar.jar mykeyid
Enter Passphrase for keystore:

$ unzip -c myjar.jar META-INF/MANIFEST.MF
Archive:  myjar.jar
  inflating: META-INF/MANIFEST.MF
Manifest-Version: 1.0
Created-By: 1.6.0_17 (Apple Inc.)
Main-Class: MyMainClass
Name: MyMainClass.class
SHA1-Digest: 2jmj7l5rSw0yVb/vlWAYkK/YBwk=
mprudhom
I tried it again and still my MANIFEST.MF is overwritten. I am on Windows XP though.
FelixM
Windows will not overwrite the manifest either.
AlBlue
I am stumped, now it works. Maybe something went wrong when the JARs were created.
FelixM
What does your manifest look like? I wonder if the OSGi package declarations in the manifest are being overwritten by jarsigner's.
mprudhom
A: 

This seems to be a JDK issue. With 1.5.0_16, the jarsigner overwrites my existing MANIFEST.MF, but with 1.6.0_13 everything works fine.

FelixM