Automatically Sign JARs using Ant and Bash
This guide is more towards Netbeans project, but it can be used as a reference for you to customize the script to suit your needs.
The signer bash file:
1 2 3 4 | #!/bin/bash find . -name "*.jar" -exec jarsigner -keystore /path/to/your/key -storepass yourpassword '{}' yourkeystorename \; echo 'JARs signed'; exit 0 |
This script will actually search all files ending with .jar from the current directory recursively and then sign it. This means, it can be used separately without ant script. Just make it executeable and run it.
Put this in the last line of your build.xml but it must before the closing tag of the “project” (build.xml can be found in your main project directory)
1 2 3 4 5 6 7 8 | <project> . . . <target name="-post-jar"> <exec dir="${dist.dir}" executable="/path/to/your/signer" os="Linux" /> </target> </project> |
This script will basically sign the jars after all the jars has been build. Please note that it’s better if you set all the path using absolute type of path.
After this, you just have to use Clean and Build to automatically generate the JARs and also automatically sign it. This script will also sign all of your libraries. Good luck :)












/path/to/your/key
didn’t understand this argument.
what should be here.
path to ks file or path to .cer file ?
abc
27 Apr 10 at 02:32 PM
@abc
It’s the path to your generated key (keystore)
amree
27 Apr 10 at 02:42 PM
I have been trying and researching for the last week on how to do this. Im on ubuntu and run your code
first I cd to unsigned directory, then;
find . -name “*.apk” -exec jarsigner -keystore /home/andrew/bin/my-key.keystore -storepass abcd ‘{}’ my-key.keystore \;
execute this and get back;
jarsigner: Certificate chain not found for: my-key.keystore. my-key.keystore must reference a valid KeyStore key entry containing a private key and corresponding public key certificate chain.
quadruple checked the keystore path and everything else. Im jarsigning APK’s instead of jars. For Android Development
Any help?
Andrew
1 Aug 10 at 08:33 AM
@Andrew
I’m not sure about signing APK’s, I’ve tried removing the key to somewhere else but I’m getting different error, so, maybe you should change the signing command to something else, the commands is after -exec
amree
1 Aug 10 at 09:39 AM