Maven 私服 unable to find valid certification path to requested target 错误

The error message you encountered "sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target" indicates that during the SSL/TLS handshake, the certificate Path validation failed. This is usually caused by missing or untrusted certificates, and Maven cannot establish a secure connection with the remote repository.

In order to solve this problem, you can try the following steps:

  1. Import certificate: Obtain a certificate from a remote repository and import it into the local Java keystore. This allows Maven to trust the certificate and establish a secure connection. You can import certificates using the command-line tools provided with the Java Development Kit (JDK) keytool. The following are example commands:

    keytool -import -alias my-cert -keystore <密钥库路径> -file <证书路径>
    

    eg

    keytool -import -alias my-cert -keystore C:\Java\jdk1.8.0_271\jre\lib\security\cacerts -file C:\Users\12892\Desktop\xxx
    

    Replace <密钥库路径>with the path to your Java keystore file (for example cacerts) and <证书路径>with the path to your certificate file. You may need to provide a password for the keystore, which is usually the default changeit.

Pro-test, use this step to solve the problem

  1. Explicitly trust the certificate in Maven settings: Add the following configuration to your settings.xmlfile to explicitly trust the remote repository's certificate:

    <settings>
      ...
      <profiles>
        <profile>
          <id>trust-repository-certificate</id>
          <activation>
            <activeByDefault>true</activeByDefault>
          </activation>
          <repositories>
            <repository>
              <id>my-repository</id>
              <url>https://example.com/repository</url>
              <releases>
                <enabled>true</enabled>
              </releases>
              <snapshots>
                <enabled>true</enabled>
              </snapshots>
              <pluginSnapshots>
                <enabled>true</enabled>
              </pluginSnapshots>
              <trustCertificates>true</trustCertificates>
              <certificatePath>/证书路径</certificatePath>
            </repository>
          </repositories>
        </profile>
      </profiles>
      ...
    </settings>
    

    Replace my-repository, , https://example.com/repositoryand /证书路径with the appropriate values ​​for your repository and certificate.

  2. Disable certificate verification (not recommended): As a last resort, you can disable certificate verification in Maven settings. However, this is not recommended as it reduces security and exposes you to potential security risks. To disable certificate verification, settings.xmladd the following configuration to the file:

    <settings>
      ...
      <ssl>
        <trustAll>true</trustAll>
      </ssl>
      ...
    </settings>
    

    By <trustAll>setting to true, Maven will trust all certificates, including self-signed or invalid certificates. Again, this is not recommended for production environments.

Guess you like

Origin blog.csdn.net/Hong_pro/article/details/131185583