How to sign JAR by java keystore and Maven

This post describes how can you sign your JAR files by maven and JAVA keystore.




Prepare JKS keystore

Generate self-signed certificate

If you don’t have any personal certificate you can generate on by this command

keytool -genkey -alias my_certificate_alias -keyalg RSA -keysize 4096 -keystore keystore.jks

Substitute “my_certificate_alias” by you own alias in command.

Follow the wizard.

Import existing certificate

If you have an existing personal certificate (in PFX format)  you can import it to keystore by following commands.

keytool -importkeystore -srckeystore mypfxfile.pfx -srcstoretype pkcs12 -destkeystore keystore.jks -deststoretype JKS




Modify you pom.xml file

Add these lines to your project pom.xml file





Compile and sign JARs by MAVEN

Go to your project root folder (where is located pom.xml) and run command.  Don’t forgot modify KEY_STORE_PASSWORD, PATH_TO_JKS_FILE and PATH_TO_JKS_FILE by your current settings.

mvn clean package -Dkeystore.password=KEY_STORE_PASSWORD -Dkeystore.path=PATH_TO_JKS_FILE -Dkeystore.alias=CERTIFICATE_ALIAS


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.