How can I sign an OSGi package with Ant without overwriting the contents of MANIFEST.MF?

I have an Eclipse plugin for which I am creating a JAR with the OSGi package with Ant. I would like to sign them using the Ant task, but this overwrites the contents of MANIFEST.MF with class signatures, which makes OSGi packages unusable. The JDK jarsigner tool has the same behavior. Eclipse PDE has this functionality, but as far as I know, you can only use it from Eclipse. I want to be able to run my Ant construct from the command line. Does anyone know an easy way to add class signatures to MANIFEST.MF instead of writing it?

+3
source share
2 answers

, . 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=
+2

, , JDK. 1.5.0_16 jarsigner MANIFEST.MF, 1.6.0_13 .

+2

Source: https://habr.com/ru/post/1725229/


All Articles