title: Run Grails 3 standalone jar/war with HTTPS
body: <p>I can run my Grails 3.3.8 application with HTTPS by using <code>-https</code> argument (<a href="https://docs.grails.org/latest/ref/Command%20Line/run-app.html" rel="nofollow noreferrer">https://docs.grails.org/latest/ref/Command%20Line/run-app.html</a>).</p>
  
  <p><code>grails run-app -https</code></p>
  
  <p>Application is accessible on <a href="https://localhost:8444" rel="nofollow noreferrer">https://localhost:8444</a> (I use custom port, 8443 is default).</p>
  
  <p>I have created a runnable <code>war</code> file using a <code>grails package</code> command, as mentioned in <a href="https://docs.grails.org/latest/guide/deployment.html" rel="nofollow noreferrer">https://docs.grails.org/latest/guide/deployment.html</a>. After executing</p>
  
  <p><code>java -jar PATH_TO_APP\myapp-0.1.war</code></p>
  
  <p>application runs correctly on <a href="http://localhost:8080" rel="nofollow noreferrer">http://localhost:8080</a>.</p>
  
  <h3>Problem</h3>
  
  <p>I can't figure out though how to run this <code>jar</code> with <code>-https</code> argument, so it's accessible on <a href="https://localhost:8444" rel="nofollow noreferrer">https://localhost:8444</a> - as with <code>grails run-app -https</code>. Can I make runnable <code>jar/war</code> run in HTTPS mode? Or maybe I can default my application to run with <code>-https</code>? </p>
  
  <h3>What I have tried:</h3>
  
  <ul>
  <li>Executing <code>jar</code> with <code>--Dserver.port.https=8444</code> parameter - to no effect.</li>
  <li>Executing <code>grails package -https</code> - I don't know what I expected.</li>
  <li>The plugin <a href="https://grails.org/plugin/standalone" rel="nofollow noreferrer">https://grails.org/plugin/standalone</a>, which looks like it could help - unfortunately unavailable for Grails 3.</li>
  </ul>
  
  <h3>Additional info</h3>
  
  <p>I have configured this application to use a certificate and custom port, but I don't think it matters an this point:</p>
  
  <p>-> <code>build.gradle</code>.</p>
  
  <pre><code>bootRun {
      jvmArgs("-Dspring.output.ansi.enabled=always")
      addResources = true
      String springProfilesActive = "spring.profiles.active"
      systemProperty springProfilesActive,     System.getProperty(springProfilesActive)
      systemProperty "server.port", "8444"
      systemProperty "server.ssl.enabled", "true"
      systemProperty "server.ssl.key-store", System.getProperty("user.home") + "/certificates/cert.p12"
      systemProperty "server.ssl.key-store-password", "secret"
      systemProperty "server.ssl.key-password", "secret"
  }
  </code></pre>
  
  <h3>Specification:</h3>
  
  <ul>
  <li>System: Windows 10</li>
  <li>JDK: 1.8.0_191-b12</li>
  <li>Grails: 3.3.8</li>
  </ul>
  
  <hr>
  
  <h3>Edit: I tried using @erichelgeson answer.</h3>
  
  <p>I re-exported my certificate with an alias <code>tomcat</code>:</p>
  
  <p><code>openssl pkcs12 -export -out ia.p12 -inkey ia.key -in ia.crt -chain -CAfile ca.crt -name tomcat</code>,</p>
  
  <p>and imported it with <code>keystore</code> command (I'm on Windows using Windows Subsystem for Linux)</p>
  
  <p><code>/mnt/c/Program\ Files/Java/jdk1.8.0_191/bin/keytool.exe -importkeystore -srckeystore cert.p12 -srcstoretype pkcs12 -srcalias tomcat -destkeystore keystore.jks -deststoretype jks -deststorepass secret -destalias tomcat</code>,</p>
  
  <p>and then migrated it to PKCS12 after keystore warning</p>
  
  <p><code>/mnt/c/Program\ Files/Java/jdk1.8.0_191/bin/keytool.exe -importkeystore -srckeystore keystore.jks -destkeystore keystore.jks -deststoretype pkcs12</code>.</p>
  
  <p>I placed <code>keystore.jks</code> in root of application folder (I also tried <code>/src/main/resources</code>) and modified my <code>application.yml</code> file by adding</p>
  
  <pre><code>server:
    port: 8444
    ssl:
      key-password: secret
      key-store-password: secret
      key-store: keystore.jks
      key-store-type: PKCS12
      key-alias: tomcat
  </code></pre>
  
  <p>Application won't start throwing error <code>DerInputStream.getLength(): lengthTag=109, too big</code> or - after commenting out <code>key-store-type: PKCS12</code>: <code>Alias name [tomcat] does not identify a key entry</code>.</p>