30

My requirement is to import a certificate for maven repositories into the global keystore.

The certificate file is named maven-cacert.cer .

I am using following command from C:\Program Files\Java\jdk1.6.0_20\bin\ from cmd

keytool -importcert -trustcacerts -alias c:\maven-cacert.cer -file c:\maven-cacert.cer.der -keystore $JAVA_HOME\jre\lib\security\cacerts

as maven-cacert.cer file is in C directory

after pressing enter it asked to put password and after giving password it is saying like

keytool error: java.io.FileNotFoundException: $JAVA_HOME\jre\lib\security\cacerts (The system cannot find the path specified

I also tried

   keytool -importcert -trustcacerts -alias c:\maven-cacert.cer -file c:\maven- cacert.cer.der -keystore \usr\java/jdk1.6.0_20/bin/java\jre\lib\security\cacerts

but getting same output

Please help what is going wrong with my command while cacerts file is inside $JAVA_HOME\jre\lib\security\ directory.

Neha Shukla
  • 3,572
  • 5
  • 38
  • 69

7 Answers7

43

Try using "%JAVA_HOME%\jre\lib\security\cacerts"

Quincy
  • 4,393
  • 3
  • 26
  • 40
  • Now its not asking for password and giving keytool error: java.lang.RuntimeException: Usage error, Files\Java\jdk1.6.0_20\jre\lib\security\cacerts is not a legal command – Neha Shukla May 28 '14 at 06:08
  • 4
    try adding double quotes around it – Quincy May 28 '14 at 06:13
29

If you are using OpenJDK then the path for cacerts will not be available in

"%JAVA_HOME%"/jre/lib/security/cacerts

it will be available in path

"%JAVA_HOME%"/lib/security/cacerts

Matt Ke
  • 3,599
  • 12
  • 30
  • 49
Raghav2650
  • 311
  • 3
  • 5
8

keytool -importcert -trustcacerts -alias mycert -file c:\maven-cacert.cer.der -keystore "%JAVA_HOME%"\jre\lib\security\cacerts

You also had a problem with alias. It's a name, not a file. You need to quote the "%JAVA_HOME%", because it has a space inside.

Oleg Gryb
  • 5,122
  • 1
  • 28
  • 40
5

Use Bellow command to import the certificate in cacerts

  1. Run command prompt as Administrator
  2. cd C:\Program Files\Java\jdk1.6.0_45\jre\bin
  3. keytool -import -trustcacerts -file "certpath\certname.cer" -alias "cert_alias" -keystore "%JAVA_HOME%"/jre/lib/security/cacerts
  4. To view certificate keytool -list -keystore "%JAVA_HOME%"/jre/lib/security/cacerts -alias cert_alias
2

For some reason, I think JAVA_HOME was not defined for me. I just used the full path. Running from the Desktop folder, my full command is:

"C:\Program Files\Java\jre1.8.0_77\bin\keytool" -import -alias fiddlercert -file fiddlerRoot.cer -keystore "C:\Program Files\Java\jre1.8.0_77\lib\security\cacerts" -storepass changeit
Mogsdad
  • 44,709
  • 21
  • 151
  • 275
Henry
  • 2,870
  • 1
  • 25
  • 17
1

What is your OS? If you are on Windows, can you try replacing $JAVA_HOME with %JAVA_HOME% and see how it goes?

Thanks, Anuj

1

I tried with following command in cmd of windows, it has worked finally:

"%JAVA_HOME%"\bin\keytool.exe -import -trustcacerts -alias *Certificate filename* -file *full path of certificate location ending with certificatename* -keystore "%JAVA_HOME%"\lib\security\cacerts
buddemat
  • 4,552
  • 14
  • 29
  • 49