How to set up SSL/TSL to connect to server?

Hello. I am new to this XMPP stuff and all things in general as I am just a young boy. I read up that XMPP is the #1 platform for instant messaging so I am now trying to make a small client app to see how everything works. I am most comfortable in Java so I searched for the best XMPP Library for Java and found Smack 4.1.2. However, I am having a problem connecting to a server.

My code is as follows:

public static void main(String[] args) throws SmackException, IOException, XMPPException, NoSuchAlgorithmException {
      XMPPTCPConnectionConfiguration.Builder config = XMPPTCPConnectionConfiguration.builder();         config.setUsernameAndPassword("johntest3","johntest3");
     config.setServiceName("wtfismyip.com");
     config.setHost("wtfismyip.com");
     config.setDebuggerEnabled(true);
     config.setSecurityMode(ConnectionConfiguration.SecurityMode.required);
     System.setProperty("javax.net.ssl.trustStore", "keystore.jks");
          XMPPTCPConnection Connection = new XMPPTCPConnection(config.build());
     try {
         Connection.connect();
     /*    System.out.println(mConnection.isConnected());*/
     } catch (SmackException | IOException | XMPPException e) {
         e.printStackTrace();
     }
  }

Now I am not sure what I am doing, I just generated a random certificate with my login credentials as my name called keystore.jks and put that in there. It sends and receives a few stanzas but then gets the following error:

12:16:29 AM SENT (0): <stream:stream xmlns='jabber:client' to='wtfismyip.com' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' from='johntest3@wtfismyip.com' xml:lang='en'>
12:16:29 AM RECV (0): <?xml version='1.0'?><stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' id='4276879633' from='wtfismyip.com' version='1.0' xml:lang='en'>
12:16:29 AM RECV (0): <stream:features><starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'><required/></starttls><c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='http://www.process-one.net/en/ejabberd/' ver='0vz9SwDO2HQa56GNLO1ylpEPehs='/><register xmlns='http://jabber.org/features/iq-register'/></stream:features>
12:16:29 AM SENT (0): <starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'></starttls>
12:16:29 AM RECV (0): <proceed xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>
org.jivesoftware.smack.SmackException: 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
  at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.parsePackets(XMPPTCPConnection.java:1008)
  at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader.access$200(XMPPTCPConnection.java:935)
  at org.jivesoftware.smack.tcp.XMPPTCPConnection$PacketReader$1.run(XMPPTCPConnection.java:950)
  at java.lang.Thread.run(Thread.java:745)

I left my login credentials in there in hopes that it may help diagnose the problem. I would greatly appreciate any help I could get. Thank you very much.

Were you able to find solution? I checked lots of post regarding this PKIX path building failed error when use TSL. I couldn’t yet find any solution. Everything work fine when I disable security with ConfigurationBuilder.setUseHttps(true).

I even tried with DummySSLSocketFactory by setting setSocketFactory but it still not picked up it.