title: How to add server certificate into java application in eclipse
body: <p>I've got a server application which uses:</p>
  
  <pre><code>import javax.net.ssl.SSLServerSocket;
  import javax.net.ssl.SSLServerSocketFactory;
  import javax.net.ssl.SSLSocket;
  </code></pre>
  
  <p>This is a java application, which is a server itself - I'm not using any virtual servers and its not a web application. It is supposed to recieve connections from client applications and handle their requests. An interlayer between client applications and a database.</p>
  
  <p>On launch it does run, but keeps spamming (cause of while (true) {}) this error:</p>
  
  <pre><code>javax.net.ssl.SSLException: No available certificate or key corresponds to the SSL cipher suites which are enabled.
      at com.sun.net.ssl.internal.ssl.SSLServerSocketImpl.checkEnabledSuites(Unknown Source)
      at com.sun.net.ssl.internal.ssl.SSLServerSocketImpl.accept(Unknown Source)
  </code></pre>
  
  <p>So, I've looked up few SSL Certificate creation guides and made a certificate using these commands:</p>
  
  <pre><code>keytool -genkey -alias serverprivate -keystore servestore -keyalg rsa -keysize 2048
  keytool -export -alias serverprivate -keystore servestore -rfc -file server.cer
  </code></pre>
  
  <p>And imported it to my local certificate storage, so I can test it with my client application:</p>
  
  <pre><code>keytool -import -alias trustservercert -file server.cer -keystore clienttruststore
  </code></pre>
  
  <p>All of this was done in my $JAVA_HOME\bin directory. I also updated my eclipse.ini file with</p>
  
  <pre><code>-vm
  $JAVA_HOME\bin\javaw.exe
  </code></pre>
  
  <p>so eclipse will use my jdk7 virtual machine to run applications.</p>
  
  <p>Same time I have tried copying <code>server.cer</code> and <code>servestore</code> files into both $ECLIPSE_HOME and application home directories.</p>
  
  <p>The result is: same error message. It doesn't stop the application from running, but it remains.</p>
  
  <p>Would really appreciate some help here. What am I doing wrong? Maybe there's a cool, detailed, newbie friendly guide on creating applications with SSL, which I couldn't find?</p>