DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report

Invalid keystore format and ‘keytool genkey’ issues during Jar signing

Mick Knutson user avatar by
Mick Knutson
·
Mar. 23, 11 · Interview
Like (0)
Save
Tweet
Share
13.49K Views

Join the DZone community and get the full member experience.

Join For Free

I have been working on creating keystores and signing jars today, and have run into some interesting findings, and some interesting but obscure errors during this process.

I have the following maven plugin that I wanted to use to sign my jar with my keystore certificate:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>${plugin-jar-version}</version>
<executions>
<execution>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
<configuration>
<keystore>src/main/keystore</keystore>
<alias>3166_javaee</alias>
<storepass>3166_javaee</storepass>
<signedjar>${project.build.directory}/signed/${project.build.finalName}.jar</signedjar>
<verify>true</verify>
</configuration>
</plugin>

Running this maven command:

mvn clean install -e

Before I created the keystore.

Then I run the jar signing with a missing keystore, then I get the following error:

[INFO]
[INFO] --- maven-jar-plugin:2.3.1:jar (default-jar) @ chapter02 ---
[INFO] Building jar: C:\usr\SYNCH\PACKT\3166\Chapters_Code\ch02\target\chapter02-1.0.2.jar
[INFO]
[INFO] --- maven-jar-plugin:2.3.1:sign (default) @ chapter02 ---
[INFO] jarsigner error: java.lang.RuntimeException: keystore load: C:\usr\SYNCH\PACKT\3166\Chapters_Code\ch02\src\main\keystore (The system cannot find the file specified)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 12.110s
[INFO] Finished at: Sat Feb 12 09:47:26 EST 2011
[INFO] Final Memory: 12M/29M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-jar-plugin:2.3.1:sign (default) on project chapter02: Result of cmd.exe /X /C "C:\usr\bin\Java\jdk1.6.0_23\jre\..
\bin\jarsigner.exe -keystore src/main/keystore -storepass 3166_javaee -signedjar C:\usr\SYNCH\PACKT\3166\Chapters_Code\ch02\target\signed\chapter02-1.0.2.jar C:\usr\SYNCH\PACK
T\3166\Chapters_Code\ch02\target\chapter02-1.0.2.jar 3166_javaee" execution is: '1'. -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-jar-plugin:2.3.1:sign (default) on project chapter02: Result of c
md.exe /X /C "C:\usr\bin\Java\jdk1.6.0_23\jre\..\bin\jarsigner.exe -keystore src/main/keystore -storepass 3166_javaee -signedjar C:\usr\SYNCH\PACKT\3166\Chapters_Code\ch02\tar
get\signed\chapter02-1.0.2.jar C:\usr\SYNCH\PACKT\3166\Chapters_Code\ch02\target\chapter02-1.0.2.jar 3166_javaee" execution is: '1'.
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:217)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:319)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:534)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
Caused by: org.apache.maven.plugin.MojoExecutionException: Result of cmd.exe /X /C "C:\usr\bin\Java\jdk1.6.0_23\jre\..\bin\jarsigner.exe -keystore src/main/keystore -storepass
3166_javaee -signedjar C:\usr\SYNCH\PACKT\3166\Chapters_Code\ch02\target\signed\chapter02-1.0.2.jar C:\usr\SYNCH\PACKT\3166\Chapters_Code\ch02\target\chapter02-1.0.2.jar 3166
_javaee" execution is: '1'.
at org.apache.maven.plugin.jar.JarSignMojo.signJar(JarSignMojo.java:345)
at org.apache.maven.plugin.jar.JarSignMojo.execute(JarSignMojo.java:242)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:107)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209)
... 19 more
[ERROR]
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

I tried to regenerate the keystore then run the signing manually, only to get the following error:

C:\usr\SYNCH\PACKT\3166\Chapters_Code\ch02>keytool  -genkey -alias 3166_javaee -keyalg RSA -keystore src/main/keystore/signing-jar.keystore -storepass 3166_javaee -keypass 316
6_javaee -dname "CN=domain"

C:\usr\SYNCH\PACKT\3166\Chapters_Code\ch02>C:\usr\bin\Java\jdk1.6.0_23\jre\..\bin\jarsigner.exe -keystore src/main/keystore -storepass 3166_javaee -signedjar C:\usr\SYNCH\PACK
T\3166\Chapters_Code\ch02\target\signed\chapter02-1.0.2.jar C:\usr\SYNCH\PACKT\3166\Chapters_Code\ch02\target\chapter02-1.0.2.jar 3166_javaee
jarsigner error: java.lang.RuntimeException: keystore load: Invalid keystore format

Now I have searched around to try to track down what this error actually is, and I have found that the error is because of the keystore path.

if I use the full keystore location ‘src/main/keystore/signing-jar.keystore’ I am able to successfully sign my jar:

C:\usr\SYNCH\PACKT\3166\Chapters_Code\ch02>C:\usr\bin\Java\jdk1.6.0_23\jre\..\bin\jarsigner.exe -keystore src/main/keystore/signing-jar.keystore -storepass 3166_javaee -signed
jar C:\usr\SYNCH\PACKT\3166\Chapters_Code\ch02\target\signed\chapter02-1.0.2.jar C:\usr\SYNCH\PACKT\3166\Chapters_Code\ch02\target\chapter02-1.0.2.jar 3166_javaee

Warning:
The signer certificate will expire within six months.

Glad to have this solved.

From http://www.baselogic.com/blog/development/java-javaee-j2ee/invalid-keystore-format-and-keytool-genkey-issues-during-jar-signing

JAR (file format)

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • 11 Observability Tools You Should Know
  • Testing Level Dynamics: Achieving Confidence From Testing
  • gRPC on the Client Side
  • Cloud Performance Engineering

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: