Usage

Brief examples on how to use the goals. For full documentation, click here.

changeAlias Goal

How to configure keytool:changeAlias using pom.xml

For the example, we will attach the execution to the generate-resources phase.

<project>
  ...
  <packaging>pom</packaging>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>keytool-maven-plugin</artifactId>
        <version>1.6-SNAPSHOT>/version>
        <executions>
          <execution>
            <goals>
              <goal>changeAlias</goal>
            </goals>
            <phase>generate-resources</phase>
          </execution>
        </executions>
        <configuration>
          <keystore>/path/to/your/keystore</keystore>
          <storepass>storepass</storepass>
          <keypass>keypass</keypass>
          <alias>foo_alias</alias>
          <destalias>new_alias</destalias>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

How to use keytool:changeAlias specifying parameters on the command line

mvn keytool:changeAlias -Dkeystore=/path/to/your/keystore -Dstorepass=storepass -Dkeypass=keypass -Dalias=foo_alias \
 -Ddestalias=new_alias

changeKeyPassword Goal

How to configure keytool:changeKeyPassword using pom.xml

For the example, we will attach the execution to the generate-resources phase.

<project>
  ...
  <packaging>pom</packaging>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>keytool-maven-plugin</artifactId>
        <version>1.6-SNAPSHOT>/version>
        <executions>
          <execution>
            <goals>
              <goal>changeKeyPassword</goal>
            </goals>
            <phase>generate-resources</phase>
          </execution>
        </executions>
        <configuration>
          <keystore>/path/to/your/keystore</keystore>
          <alias>foo_alias</alias>
          <storepass>storepass</storepass>
          <keypass>keypass</keypass>
          <newPassword>newpassword</newPassword>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

How to use keytool:changeKeyPassword specifying parameters on the command line

mvn keytool:changeKeyPassword -Dkeystore=/path/to/your/keystore -Dstorepass=storepass -Dalias=foo_alias \
 -Dkeypass=keypass -DnewPassword=newPassword

changeStorePassword Goal

How to configure keytool:changeStorePassword using pom.xml

For the example, we will attach the execution to the generate-resources phase.

<project>
  ...
  <packaging>pom</packaging>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>keytool-maven-plugin</artifactId>
        <version>1.6-SNAPSHOT>/version>
        <executions>
          <execution>
            <goals>
              <goal>changeStorePassword</goal>
            </goals>
            <phase>generate-resources</phase>
          </execution>
        </executions>
        <configuration>
          <keystore>/path/to/your/keystore</keystore>
          <storepass>storepass</storepass>
          <newPassword>newPassword</newPassword>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

How to use keytool:changeStorePassword specifying parameters on the command line

mvn keytool:changeStorePassword -Dkeystore=/path/to/your/keystore -Dstorepass=storepass -DnewPassword=newPassword

deleteAlias Goal

How to configure keytool:deleteAlias using pom.xml

For the example, we will attach the execution to the generate-resources phase.

<project>
  ...
  <packaging>pom</packaging>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>keytool-maven-plugin</artifactId>
        <version>1.6-SNAPSHOT>/version>
        <executions>
          <execution>
            <goals>
              <goal>deleteAlias</goal>
            </goals>
            <phase>generate-resources</phase>
          </execution>
        </executions>
        <configuration>
          <keystore>/path/to/your/keystore</keystore>
          <storepass>storepass</storepass>
          <alias>foo_alias</alias>
          <keypass>keypass</keypass>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

How to use keytool:deleteAlias specifying parameters on the command line

mvn keytool:deleteAlias -Dkeystore=/path/to/your/keystore -Dstorepass=storepass -Dalias=foo_alias -Dkeypass=keypass

exportCertificate Goal

How to configure keytool:exportCertificate using pom.xml

For the example, we will attach the execution to the generate-resources phase.

<project>
  ...
  <packaging>pom</packaging>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>keytool-maven-plugin</artifactId>
        <version>1.6-SNAPSHOT>/version>
        <executions>
          <execution>
            <goals>
              <goal>exportCertificate</goal>
            </goals>
            <phase>generate-resources</phase>
          </execution>
        </executions>
        <configuration>
          <keystore>/path/to/your/keystore</keystore>
          <storepass>storepass</storepass>
          <alias>foo_alias</alias>
          <keypass>keypass</keypass>
          <file>/path/to/exportFile</file>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

How to use keytool:exportCertificate specifying parameters on the command line

mvn keytool:exportCertificate -Dkeystore=/path/to/your/keystore -Dstorepass=storepass -Dalias=foo_alias -Dkeypass=keypass -Dfile=/path/to/exportFile

generateCertificate Goal

How to configure keytool:generateCertificate using pom.xml

For the example, we will attach the execution to the generate-resources phase.

<project>
  ...
  <packaging>pom</packaging>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>keytool-maven-plugin</artifactId>
        <version>1.6-SNAPSHOT>/version>
        <executions>
          <execution>
            <goals>
              <goal>generateCertificate</goal>
            </goals>
            <phase>generate-resources</phase>
          </execution>
        </executions>
        <configuration>
          <keystore>/path/to/your/keystore</keystore>
          <dname>cn=www.example.com, ou=None, L=Seattle, ST=Washington, o=ExampleOrg, c=US</dname>
          <keypass>keypass</keypass>
          <storepass>storepass</storepass>
          <alias>foo_alias</alias>
          <inFile>/path/to/certificateRequest</inFile>
          <outFile>/path/to/exportCertificate</outFile>
          <sigalg>SHA1withDSA</sigalg>
          <ext></ext>
          <validity>100</validity>
          <startdate>2012/01/01</startdate>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

How to use keytool:generateCertificate specifying parameters on the command line

mvn keytool:generateCertificate -Dkeystore=/path/to/your/keystore -Dstorepass=storepass -Dkeypass=keypass \
  -Dalias=foo_alias -DinFile=/path/to/certificateRequest -DoutFile=/path/to/exportCertificate \
  -Ddname="cn=www.example.com, ou=None, L=Seattle, ST=Washington, o=ExampleOrg, c=US" \
  -Dsigalg=SHA1withDSA -Dext="" -Dvalidity=100 -Dstartdate="2012/01/0"

generateCertificateRequest Goal

How to configure keytool:generateCertificateRequest using pom.xml

For the example, we will attach the execution to the generate-resources phase.

<project>
  ...
  <packaging>pom</packaging>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>keytool-maven-plugin</artifactId>
        <version>1.6-SNAPSHOT>/version>
        <executions>
          <execution>
            <goals>
              <goal>generateCertificateRequest</goal>
            </goals>
            <phase>generate-resources</phase>
          </execution>
        </executions>
        <configuration>
          <keystore>/path/to/your/keystore</keystore>
          <storepass>storepass</storepass>
          <keypass>keypass</keypass>
          <alias>foo_alias</alias>
          <dname>cn=www.example.com, ou=None, L=Seattle, ST=Washington, o=ExampleOrg, c=US</dname>
          <file>/path/to/exportCertificateRequest</file>
          <sigalg>SHA1withDSA</sigalg>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

How to use keytool:generateCertificateRequest specifying parameters on the command line

mvn keytool:generateCertificateRequest -Dkeystore=/path/to/your/keystore -Dstorepass=storepass -Dkeypass=keypass \
   -Dalias=foo_alias -Dfile=/path/to/exportCertificateRequest -Dsigalg=SHA1withDSA \
   -Ddname="cn=www.example.com, ou=None, L=Seattle, ST=Washington, o=ExampleOrg, c=US" \

generateKeyPair Goal

How to configure keytool:generateKeyPair using pom.xml

For the example, we will attach the execution to the generate-resources phase.

<project>
  ...
  <packaging>pom</packaging>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>keytool-maven-plugin</artifactId>
        <version>1.6-SNAPSHOT>/version>
        <executions>
          <execution>
            <goals>
              <goal>generateKeyPair</goal>
            </goals>
            <phase>generate-resources</phase>
          </execution>
        </executions>
        <configuration>
          <keystore>/path/to/your/keystore</keystore>
          <storepass>storepass</storepass>
          <keypass>keypass</keypass>
          <alias>foo_alias</alias>
          <dname>cn=www.example.com, ou=None, L=Seattle, ST=Washington, o=ExampleOrg, c=US</dname>
          <sigalg>SHA1withDSA</sigalg>
          <ext></ext>
          <validity>100</validity>
          <keyalg>DSA</keyalg>
          <keysize>1024</keysize>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

How to use keytool:generateKeyPair specifying parameters on the command line

mvn keytool:generateKeyPair -Dkeystore=/path/to/your/keystore -Dstorepass=storepass -Dkeypass=keypass \
  -Dalias=foo_alias -Dsigalg=SHA1withDSA -Dext="" -Dvalidity=100 -Dkeyalg=DSA -Dkeysize=1024 \
  -Ddname="cn=www.example.com, ou=None, L=Seattle, ST=Washington, o=ExampleOrg, c=US"

generateSecretKey Goal

How to configure keytool:generateSecretKey using pom.xml

For the example, we will attach the execution to the generate-resources phase.

<project>
  ...
  <packaging>pom</packaging>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>keytool-maven-plugin</artifactId>
        <version>1.6-SNAPSHOT>/version>
        <executions>
          <execution>
            <goals>
              <goal>generateSecretKey</goal>
            </goals>
            <phase>generate-resources</phase>
          </execution>
        </executions>
        <configuration>
          <keystore>/path/to/your/keystore</keystore>
          <storepass>storepass</storepass>
          <keypass>keypass</keypass>
          <alias>foo_alias</alias>
          <keyalg>DES</keyalg>
          <keysize>56</keysize>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

How to use keytool:generateSecretKey specifying parameters on the command line

mvn keytool:generateSecretKey -Dkeystore=/path/to/your/keystore -Dstorepass=storepass -Dkeypass=keypass \
    -Dalias=foo_alias -Dkeyalg=DES -Dkeysize=56

importCertificate Goal

How to configure keytool:importCertificate using pom.xml

For the example, we will attach the execution to the generate-resources phase.

<project>
  ...
  <packaging>pom</packaging>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>keytool-maven-plugin</artifactId>
        <version>1.6-SNAPSHOT>/version>
        <executions>
          <execution>
            <goals>
              <goal>importCertificate</goal>
            </goals>
            <phase>generate-resources</phase>
          </execution>
        </executions>
        <configuration>
          <keystore>/path/to/your/keystore</keystore>
          <storepass>storepass</storepass>
          <keypass>keypass</keypass>
          <alias>foo_alias</alias>
          <file>/path/to/certificate</file>
          <trustcacerts>true</trustcacerts>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

How to use keytool:importCertificate specifying parameters on the command line

mvn keytool:importCertificate -Dkeystore=/path/to/your/keystore -Dstorepass=storepass -Dkeypass=keypass \
  -Dalias=foo_alias -Dfile=/path/to/certificate -Dtrustcacerts=true

list Goal

How to configure keytool:list using pom.xml

For the example, we will attach the execution to the generate-resources phase.

<project>
  ...
  <packaging>pom</packaging>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>keytool-maven-plugin</artifactId>
        <version>1.6-SNAPSHOT>/version>
        <executions>
          <execution>
            <goals>
              <goal>list</goal>
            </goals>
            <phase>generate-resources</phase>
          </execution>
        </executions>
        <configuration>
          <keystore>/path/to/your/keystore</keystore>
          <storepass>storepass</storepass>
          <keypass>keypass</keypass>
          <alias>foo_alias</alias>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

How to use keytool:list specifying parameters on the command line

mvn keytool:list -Dkeystore=/path/to/your/keystore -Dstorepass=storepass -Dkeypass=keypass -Dalias=foo_alias

printCertificate Goal

How to configure keytool:printCertificate using pom.xml

For the example, we will attach the execution to the generate-resources phase.

<project>
  ...
  <packaging>pom</packaging>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>keytool-maven-plugin</artifactId>
        <version>1.6-SNAPSHOT>/version>
        <executions>
          <execution>
            <goals>
              <goal>printCertificate</goal>
            </goals>
            <phase>generate-resources</phase>
          </execution>
        </executions>
        <configuration>
          <file>/path/to/certificate</dname>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

How to use keytool:printCertificate specifying parameters on the command line

mvn keytool:printCertificate -Dfile=/path/to/certificate

printCertificateRequest Goal

How to configure keytool:printCertificateRequest using pom.xml

For the example, we will attach the execution to the generate-resources phase.

<project>
  ...
  <packaging>pom</packaging>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>keytool-maven-plugin</artifactId>
        <version>1.6-SNAPSHOT>/version>
        <executions>
          <execution>
            <goals>
              <goal>printCertificateRequest</goal>
            </goals>
          </execution>
          <phase>generate-resources</phase>
        </executions>
        <configuration>
          <file>/path/to/certificateRequest</file>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

How to use keytool:printCertificateRequest specifying parameters on the command line

mvn keytool:printCertificateRequest -Dfile=/path/to/certificateRequest

printCRLFile Goal

How to configure keytool:printCRLFile using pom.xml

For the example, we will attach the execution to the generate-resources phase.

<project>
  ...
  <packaging>pom</packaging>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>keytool-maven-plugin</artifactId>
        <version>1.6-SNAPSHOT>/version>
        <executions>
          <execution>
            <goals>
              <goal>printCRLFile</goal>
            </goals>
            <phase>generate-resources</phase>
          </execution>
        </executions>
        <configuration>
          <file>/path/to/CRLFile</file>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

How to use keytool:printCRLFile specifying parameters on the command line

mvn keytool:printCRLFile -Dfile=/path/to/CRLFile

Genkey Goal (deprecated since 1.2)

How to configure keytool:genkey using pom.xml

<project>
  ...
  <packaging>pom</packaging>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>keytool-maven-plugin</artifactId>
        <version>1.6-SNAPSHOT>/version>
        <executions>
          <execution>
            <goals>
              <goal>genkey</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <keystore>/path/to/your/keystore</keystore>
          <dname>cn=www.example.com, ou=None, L=Seattle, ST=Washington, o=ExampleOrg, c=US</dname>
          <keypass>keypass</keypass>
          <storepass>storepass</storepass>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

How to use keytool:genkey specifying parameters on the command line

mvn keytool:genkey -Dkeystore=/path/to/your/keystore -Dstorepass=storepass -Dkeypass=keypass -Dalias=foo_alias

Clean goal

Brief examples on how to use the keytool:clean goal.

How to configure keytool:clean using pom.xml

<project>
  ...
  <packaging>pom</packaging>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>keytool-maven-plugin</artifactId>
        <version>1.6-SNAPSHOT>/version>
        <executions>
          <execution>
            <phase>clean</phase>
            <goals>
              <goal>clean</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <keystore>/path/to/your/keystore</keystore>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

How to use keytool:clean specifying parameters on the command line

mvn keytool:clean [-Dkeystore=...]

Export Goal (deprecated since 1.2)

How to configure keytool:export using pom.xml

<project>
  ...
  <packaging>pom</packaging>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>keytool-maven-plugin</artifactId>
        <version>1.6-SNAPSHOT>/version>
        <executions>
          <execution>
            <goals>
              <goal>export</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <alias>foo_alias</alias>
          <keystore>/path/to/your/keystore</keystore>
          <keypass>keypass</keypass>
          <storepass>storepass</storepass>
          <file>path_to_exported_certfile</file>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

How to use keytool:export specifying parameters on the command line

mvn keytool:export -Dkeystore=/path/to/your/keystore -Dstorepass=storepass -Dkeypass=keypass -Dalias=foo_alias -Dfile=/path/to/your/certfile

Import Goal (deprecated since 1.2)

How to configure keytool:import using pom.xml

<project>
  ...
  <packaging>pom</packaging>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>keytool-maven-plugin</artifactId>
        <version>1.6-SNAPSHOT>/version>
        <executions>
          <execution>
            <goals>
              <goal>import</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <alias>foo_alias</alias>
          <keystore>/path/to/your/keystore</keystore>
          <keypass>keypass</keypass>
          <storepass>storepass</storepass>
          <file>path_to_keystore_toimport</file>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

How to use keytool:import specifying parameters on the command line

mvn keytool:import -Dkeystore=/path/to/your/keystore -Dstorepass=storepass -Dalias=foo_alias -Dfile=/path/to/your/certfile