Home >Java >javaTutorial >How to Solve 'SunCertPathBuilderException: unable to find valid certification path to requested target' When Using Maven Behind a Proxy?

How to Solve 'SunCertPathBuilderException: unable to find valid certification path to requested target' When Using Maven Behind a Proxy?

Susan Sarandon
Susan SarandonOriginal
2024-11-18 08:58:02398browse

How to Solve

Problems using Maven and SSL behind a proxy

When attempting to use Maven behind a corporate firewall, it is necessary to configure proxy settings. However, after correctly configuring these settings, it is possible to encounter an error involving an SSL certificate and difficulties downloading from the Maven repository. The error "SunCertPathBuilderException: unable to find valid certification path to requested target" may appear.

The solution lies in resolving the proxy issue. To do so, follow these steps:

  1. Retrieve the SSL Certificate: Use a browser to navigate to https://repo.maven.apache.org/, click on the lock icon, select "View Certificate," and go to the "Details" tab. Choose "Save to File" and save the certificate as a Base 64 X.509 (.CER) file.
  2. Import the Certificate: Open a command prompt and type the following command, substituting your own paths:

    keytool -import -file C:\temp\mavenCert.cer -keystore C:\temp\mavenKeystore
  3. Configure Maven: Run the Maven command again, this time with the parameter -Djavax.net.ssl.trustStore=C:tempmavenKeystore:

    mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false -Djavax.net.ssl.trustStore=C:\temp\mavenKeystore

Optional Step:

To avoid having to repeat these steps in the future, you can set the MAVEN_OPTS environment variable. For more information on this variable, refer to the documentation.

The above is the detailed content of How to Solve 'SunCertPathBuilderException: unable to find valid certification path to requested target' When Using Maven Behind a Proxy?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn