eclipse 使用基于 ssl 证书的身份验证的 m2e

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26587085/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 22:07:36  来源:igfitidea点击:

m2e with ssl certificate-based authentication

javaeclipsemavenssl-certificatem2e

提问by Sorrow

TL;DR

TL; 博士

How to make Eclipse's built-in Maven connect to an HTTPS repository that uses certificate-based authentication?

如何使 Eclipse 的内置 Maven 连接到使用基于证书的身份验证的 HTTPS 存储库?

It seems that m2eis able to find the keystores, but unable to connect. Command-line Maven works like a charm using exactly the same keystores. Run as -> Maven buildworks with external Maven and not with the embedded one.

似乎m2e可以找到密钥库,但无法连接。命令行 Maven 使用完全相同的密钥库就像一个魅力。Run as -> Maven build与外部 Maven 一起工作,而不是与嵌入式 Maven 一起工作。

Problem

问题

I have a Maven project with a dependency. That dependency is available in a repository that uses SSL certificate-based authentication in addition to regular username-password combination. I need to make it work in Eclipse Luna, with the built-in Maven. All I am able to get is handshake_failure. Investigation of the logs shows that the built-in Maven is unable to find a matching certificate.

我有一个具有依赖项的 Maven 项目。除了常规的用户名密码组合之外,该依赖项在使用基于 SSL 证书的身份验证的存储库中可用。我需要使用内置的 Maven 使其在 Eclipse Luna 中工作。我能得到的只是handshake_failure. 对日志的调查表明,内置 Maven 无法找到匹配的证书。

When I use Run as -> Maven buildwith an external Maven, or command-line Maven, it successfully connects to the repository and fetches the artifact exactly as needed.

当我使用Run as -> Maven build外部 Maven 或命令行 Maven 时,它成功连接到存储库并完全根据需要获取工件。

The interesting thing is, both external and embedded Mavens have the same version (3.2.3).

有趣的是,外部和嵌入式 Maven 具有相同的版本 (3.2.3)。

Setup

设置

I pass these parameters through eclipse.ini:

我通过这些参数传递eclipse.ini

-Djavax.net.ssl.trustStore=java.cacerts
-Djavax.net.ssl.trustStorePassword=******
-Djavax.net.ssl.keyStore=private.cacerts
-Djavax.net.ssl.keyStorePassword=******
-Djavax.net.debug=ssl,handshake

The trustStorefile contains:

trustStore文件包含:

  • the whole certificate chain for the repository I connect to (the chain ends with a self-signed certificate), one of them being stored under the alias repository.location.url(literal repository location here, e.g. myrepository.com)
  • certificate for maven central
  • 我连接到的存储库的整个证书链(该链以自签名证书结尾),其中之一存储在别名下repository.location.url(此处的字面存储库位置,例如myrepository.com
  • Maven Central 证书

The keyStorefile contains an imported PKCS certificate under an alias of the repository.

keyStore文件在存储库的别名下包含导入的 PKCS 证书。

There seems to be no problem at all with the setup, as the command-line Maven works. If I use external Maven or command-line one, it works. If I swich to embedded one (which is always used for resolving dependencies), handshake errorshows up.

设置似乎完全没有问题,因为命令行 Maven 可以工作。如果我使用外部 Maven 或命令行,它就可以工作。如果我切换到嵌入式(它总是用于解决依赖关系),handshake error就会出现。

What am I doing wrong?I might be missing something completely obvious. Any help would be appreciated.

我究竟做错了什么?我可能遗漏了一些完全明显的东西。任何帮助,将不胜感激。

采纳答案by Alexey Sh.

I had exactly the same problem: Eclipse could not connect to external maven repository using embedded maven installation in case the repository requires a client SSL certificate.

我遇到了完全相同的问题:如果存储库需要客户端 SSL 证书,Eclipse 无法使用嵌入式 Maven 安装连接到外部 Maven 存储库。

The problem was solved by upgrading to latest jvm (in my case - 1.8.0u52) and upgrading Eclipse m2e plugin to version 1.6.1 (with Eclipse version 4.4.0).

通过升级到最新的 jvm(在我的例子中是 1.8.0u52)并将 Eclipse m2e 插件升级到 1.6.1 版(Eclipse 4.4.0 版)解决了这个问题。

回答by Uvaraj Krishna

Options that didn't work for me

对我不起作用的选项

  • Installing certificate to java > jre > lib > security > cacerts
  • Providing cacerts in java run configuration vm arguments
  • Updating eclipse to latest versions like mars or neon
  • Updating maven plugin for eclipse to 1.7.0
  • 将证书安装到 java > jre > lib > security > cacerts
  • 在 java 运行配置 vm 参数中提供 cacerts
  • 将 eclipse 更新到最新版本,如 mars 或 neon
  • 将 Eclipse 的 Maven 插件更新到 1.7.0

Steps that resolved the issue for me

为我解决问题的步骤

  • Download certificate file& add in eclipse at Preferences > Remote Systems > SSL > Add
  • Clear .m2 > repository folder of all existing files
  • Open eclipse, right-click on project and Select Maven > Update Project. Choose Force Update of Snapshots/Releases
  • 下载证书文件并在 eclipse 中添加Preferences > Remote Systems > SSL > Add
  • 清除 .m2 > 所有现有文件的存储库文件夹
  • 打开 eclipse,右键单击项目并选择Maven > Update Project。选择强制更新快照/版本

updated on 9/19/2017

2017 年 9 月 19 日更新

  • 如果没有其他工作,在您的机器上安装证书到 Java@ java > jre > lib > security > cacerts 可以提供帮助

回答by user4802011

In your run configurations select your maven build and then select the JRE tab at the top of the dialog. Put your SSL parameters into the VM arguments text-area.

在您的运行配置中,选择您的 Maven 构建,然后选择对话框顶部的 JRE 选项卡。将您的 SSL 参数放入 VM 参数文本区域。

that's what fixed it for me.

这就是为我修复它的原因。

回答by Piotr Borowczynski

I managed to fix it by setting external maven in eclipse. Eclipse->Window->Preferences->Maven->Installations->Add

我设法通过在 eclipse 中设置外部 Maven 来修复它。Eclipse->Window->Preferences->Maven->Installations->Add