Java 无法将证书导入 cacerts
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23903842/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unable to import certificate to cacerts
提问by Neha Shukla
My requirement is to import a certificate for maven repositories into the global keystore.
我的要求是将 Maven 存储库的证书导入全局密钥库。
The certificate file is named maven-cacert.cer .
证书文件名为 maven-cacert.cer 。
I am using following command from C:\Program Files\Java\jdk1.6.0_20\bin\
from cmd
我正在使用以下命令C:\Program Files\Java\jdk1.6.0_20\bin\
来自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
因为maven-cacert.cer
文件在C
目录中
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.
当cacerts
文件在$JAVA_HOME\jre\lib\security\
目录中时,请帮助我的命令出了什么问题。
采纳答案by Quincy
Try using "%JAVA_HOME%\jre\lib\security\cacerts"
尝试使用 "%JAVA_HOME%\jre\lib\security\cacerts"
回答by user3679345
What is your OS? If you are on Windows, can you try replacing $JAVA_HOME with %JAVA_HOME% and see how it goes?
你的操作系统是什么?如果您使用的是 Windows,您可以尝试将 $JAVA_HOME 替换为 %JAVA_HOME% 并看看效果如何?
Thanks, Anuj
谢谢,阿努杰
回答by Oleg Gryb
keytool -importcert -trustcacerts -alias mycert -file c:\maven-cacert.cer.der -keystore "%JAVA_HOME%"\jre\lib\security\cacerts
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.
您也遇到了别名问题。这是一个名称,而不是一个文件。您需要引用 "%JAVA_HOME%",因为它里面有一个空格。
回答by Gajendra Kumar Sahu
Use Bellow command to import the certificate in cacerts
使用 Bellow 命令导入 cacerts 中的证书
- Run command prompt as Administrator
- cd C:\Program Files\Java\jdk1.6.0_45\jre\bin
- keytool -import -trustcacerts -file "certpath\certname.cer" -alias "cert_alias" -keystore "%JAVA_HOME%"/jre/lib/security/cacerts
- To view certificate keytool -list -keystore "%JAVA_HOME%"/jre/lib/security/cacerts -alias cert_alias
- 以管理员身份运行命令提示符
- cd C:\Program Files\Java\jdk1.6.0_45\jre\bin
- keytool -import -trustcacerts -file "certpath\certname.cer" -alias "cert_alias" -keystore "%JAVA_HOME%"/jre/lib/security/cacerts
- 查看证书 keytool -list -keystore "%JAVA_HOME%"/jre/lib/security/cacerts -alias cert_alias
回答by Henry
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:
出于某种原因,我认为 JAVA_HOME 不是为我定义的。我只是使用了完整路径。从桌面文件夹运行,我的完整命令是:
"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
回答by Raghav2650
If you are using OpenJDK then the path for cacerts
will not be available in
如果您使用的是 OpenJDK,那么路径cacerts
将不可用
"%JAVA_HOME%"/jre/lib/security/cacerts
"%JAVA_HOME%"/jre/lib/security/cacerts
it will be available in path
它将在路径中可用
"%JAVA_HOME%"/lib/security/cacerts
"%JAVA_HOME%"/lib/security/cacerts