title: How to properly import a selfsigned certificate into Java keystore that is available to all Java applications by default?
body: <p>I do want to import a self signed certificate into Java so any Java application that will try to establish a SSL connection will trust this certificate.</p>
  
  <p>So far, I managed to import it in</p>
  
  <pre><code>keytool -import -trustcacerts -noprompt -storepass changeit -alias $REMHOST -file $REMHOST.pem
  keytool -import -trustcacerts -noprompt -keystore cacerts -storepass changeit -alias $REMHOST -file $REMHOST.pem
  </code></pre>
  
  <p>Still, when I try to run <a href="http://adywicaksono.wordpress.com/2007/07/15/ssl-connection-with-java/"><code>HTTPSClient.class</code></a> I still get:</p>
  
  <pre>javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target</pre>