Last Updated: February 25, 2016
·
1.625K
· alvarogarcia7

Fixing SunCertPathBuilderException caused by Maven downloading from self-signed repository

Source: https://www.liferay.com/es/web/neil.griffin/blog/-/blogs/fixing-suncertpathbuilderexception-caused-by-maven-downloading-from-self-signed-repository

If you have a Maven repository running under https with a self-signed certificate, then building a Maven project can report the following error:

Error transferring file: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

There was an Oracle blog posted by Andreas Sterbenz back on Oct 09, 2006 that helped me diagnose the problem, but that blog is no longer available. Thankfully Andreas' blog was re-posted here. For additional information, I found another blog post that was helpful.

Anyways, I fixed this problem by downloading and compiling the source for InstallCert.java (copy is available as a gist), see append 1. and running the following command:

cd C:\tmp
C:

mkdir certificates
cd certificates

mkdir com\aw\ad\util\
#copy file InstallCert to util
javac com.aw.ad.util.InstallCert

java com.aw.ad.util.InstallCert myhostname.mydomain.com

type 1

#wait for jssecacerts to be generated

This generated a file named jssecacerts in the current directory.

On Windows/Linux, this file needs to be copied to the JAVA_HOME/jre/lib/security/ directory.

this was C:\program files\java\JAVA_XXXX\jre....

On Mac needs to be copied to the JAVA_HOME/lib/security/ directory.

After I did this, Maven was able to download the artifacts from the self-signed repository.