"Maven unable to find valid certification path to requested target" 这个错误通常是因为 Maven 无法验证 SSL 证书,从而无法连接到 Maven 仓库。
解决这个问题的方法如下:
- 更新 Maven 配置文件,将 Maven 的 SSL 认证添加到信任列表中。
在 Maven 的配置文件 settings.xml 中添加以下配置:
<settings>
<mirrors>
<mirror>
<id>repo</id>
<url>https://repo.maven.apache.org/maven2</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
<profiles>
<profile>
<id>ssl</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<maven.wagon.http.ssl.insecure>true</maven.wagon.http.ssl.insecure>
<maven.wagon.http.ssl.allowall>true</maven.wagon.http.ssl.allowall>
</properties>
</profile>
</profiles>
</settings>
- 如果 Maven 配置文件不起作用,您可以在命令行中设置 Java 环境变量。
在命令行中运行以下命令:
export MAVEN_OPTS="-Djavax.net.ssl.trustStore=/path/to/cacerts"
其中 /path/to/cacerts 是您 Java 安装目录中的 cacerts 文件的路径。
- 如果以上两种方法都无法解决问题,您可以尝试手动导入 SSL 证书。
您可以使用以下命令从 Maven 仓库获取 SSL 证书:
openssl s_client -connect repo.maven.apache.org:443 < /dev/null | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > /tmp/repo.crt
然后将证书添加到 Java 信任库中:
sudo keytool -import -alias maven -keystore $JAVA_HOME/jre/lib/security/cacerts -file /tmp/repo.crt
如果您无法访问 repo.maven.apache.org,请将其替换为您正在使用的 Maven 仓库的主机名。
本文内容转载自:https://juejin.cn/s/maven%20unable%20to%20find%20valid%20certification%20path%20to%20requested%20target%E6%80%8E%E4%B9%88%E8%A7%A3%E5%86%B3
浙公网安备 33010602011771号