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