Uploaded image for project: 'Keikai'
  1. Keikai
  2. KEIKAI-650

Load a license file from an executable WAR



    • New Feature
    • Resolution: Fixed
    • Major
    • 5.12.0
    • None
    • None
    • Security Level: Jimmy
    • None


      User Story

      As an application developer, I want keikai can load a license file from an executable WAR, so that I can deploy my application with spring-boot + embedded tomcat to a production environment

      Acceptance Criteria

      when running an application with an executable WAR, keikai still can load a license file from the default path: metainfo/keikai/license

      steps to reproduce

      the attached zip is a project that can produce an executable war
      1. put a keikai license file in the default path
      2. run mvn package
      3. java -jar demo.war.

      current result

      no license info printed in the log

      expected result

      print license information


      The file path in a WAR archive is:
      java.io.File doesn't understand the !/ syntax

      URL resource = Runtime.class.getResource("/metainfo/keikai/license/");
      URLConnection connection = resource.openConnection();
      InputStream inputStream = connection.getInputStream();

      If you need to list all files in a directory inside the WAR, it's a bit more complex. You would need to get a URLConnection, check if it's an instance of JarURLConnection, and if it is, get the JarFile from the connection and iterate over its entries. Each entry in a JarFile represents a file or directory in the WAR. Here's an example:

      URL dirURL = getClass().getClassLoader().getResource("metainfo/keikai/license/");
      URLConnection conn = dirURL.openConnection();
      if (conn instanceof JarURLConnection) {
        JarFile jarFile = ((JarURLConnection) conn).getJarFile();
        Enumeration<JarEntry> entries = jarFile.entries(); //gives ALL entries in jar
        while(entries.hasMoreElements()) {
          String name = entries.nextElement().getName();
          if (name.startsWith("metainfo/keikai/license/")) { //filter according to the path

      This will print out all paths that start with "metainfo/keikai/license/" in the WAR file. You may need to adjust the code to fit your exact needs.

      Benefits of Using an Executable WAR in production environments:

      • Simplicity: An executable WAR file simplifies deployment because it includes both your application and an embedded server (like Tomcat or Jetty). This means you don't need to install and configure a separate server, and you can start your application with a simple command like java -jar myapp.war.
      • Consistency: Since the server is embedded in the WAR, you can be sure that the server's configuration and version are the same in every environment (development, testing, production, etc.). This can prevent bugs that occur when an application works on one server but not another.
      • Spring Boot compatibility: If you're using Spring Boot, you're probably already using executable WARs or JARs, because this is the style of deployment that Spring Boot encourages.


        Issue Links



              DevChu DevChu
              hawk hawk
              0 Vote for this issue
              2 Start watching this issue