title: "mvn spring-boot:run" works, but executing a Spring Boot fat jar fails
body: <p><strong>Short description of my problem</strong>: <code>mvn spring-boot:run</code> allows me to run my Spring Boot application without issues, while <code>mvn package spring-boot:repackage</code> produces a self executable fat jar that fails to start with the exception <code>org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.context.ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.</code></p>
  
  <p><em>I have the suspect that the problem is related to Proguard, however I'm not sure.</em></p>
  
  <p>I've already spent hours reading related problems on Stack Overflow (this exception seems a common problem), however I didn't find the cause of the error neither the solution. I also don't understand why I should have to modify my code (like in a lot of discussion that I've read) considering that with <code>mvn spring-boot:run</code> it works.</p>
  
  <p><strong>Long description of the problem...</strong></p>
  
  <p>My Spring Boot app runs fine in Netbeans 9 and I need to a fat self-executable jar to deploy the app in a CentOS server. I know that Netbeans runs Spring Boot by <code>mvn spring-boot:run</code>.</p>
  
  <p>In my development machine, I created two script: the first one executes Spring Boot like Netbeans does, and it works; the second tries to produce the executable jar. In the scripts I change the Java path because I have multiple versions of Java (the default is Java 10).</p>
  
  <p><strong>First script:</strong></p>
  
  <pre><code># Changes the current dir and remove the target dir
  cd ~/Projects/AppServer/
  rm -fR target
  
  # Changes the Bash path, adding maven and replacing Java10 with Java8.
  # It also set the Java home dir.
  JAVA_HOME="/usr/lib/jvm/java-8-oracle/"
  export M2_HOME=~/netbeans-9/java/maven
  export PATH=${M2_HOME}/bin:${PATH}
  export PATH=$(echo "$PATH" | sed -e 's#java-10-oracle#java-8-oracle#g')
  
  # Execute the Spring Boot server
  mvn -Dfile.encoding=UTF-8 spring-boot:run
  </code></pre>
  
  <p><strong>Output:</strong> (I use an external link because there is a limit of length in the body of Stack Overflow questions)
  <a href="https://gist.github.com/jsfan3/e63ff919e90377e567a78e508300e186" rel="nofollow noreferrer">https://gist.github.com/jsfan3/e63ff919e90377e567a78e508300e186</a></p>
  
  <p><strong>Second script</strong>:  </p>
  
  <pre><code># Changes the current dir and remove the target dir
  cd ~/Projects/AppServer/
  rm -fR target
  
  # Changes the Bash path, adding maven and replacing Java10 with Java8.
  # It also set the Java home dir.
  JAVA_HOME="/usr/lib/jvm/java-8-oracle/"
  export M2_HOME=~/netbeans-9/java/maven
  export PATH=${M2_HOME}/bin:${PATH}
  export PATH=$(echo "$PATH" | sed -e 's#java-10-oracle#java-8-oracle#g')
  
  # Create a fat jar to execute the Spring Boot server
  mvn -Dfile.encoding=UTF-8 package spring-boot:repackage
  
  # Tries to execute
  cd target
  ./app-1.0.0-SNAPSHOT.jar
  </code></pre>
  
  <p><strong>Output</strong>: (I use an external link because there is a limit of length in the body of Stack Overflow questions) 
  <a href="https://gist.github.com/jsfan3/5b4a88b6aca5caa061eab57eed8db047" rel="nofollow noreferrer">https://gist.github.com/jsfan3/5b4a88b6aca5caa061eab57eed8db047</a></p>
  
  <p>My <code>pom.xml</code>:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;groupId&gt;com.example.server&lt;/groupId&gt;
      &lt;artifactId&gt;app&lt;/artifactId&gt;
      &lt;version&gt;1.0.0-SNAPSHOT&lt;/version&gt;
      &lt;packaging&gt;jar&lt;/packaging&gt;
  
      &lt;name&gt;AppServerCode&lt;/name&gt;
      &lt;description&gt;Teammate&lt;/description&gt;
  
      &lt;parent&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
          &lt;version&gt;2.0.3.RELEASE&lt;/version&gt;
          &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
      &lt;/parent&gt;
  
      &lt;properties&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
          &lt;project.reporting.outputEncoding&gt;UTF-8&lt;/project.reporting.outputEncoding&gt;
          &lt;java.version&gt;1.8&lt;/java.version&gt;
          &lt;skip.it&gt;true&lt;/skip.it&gt;
      &lt;/properties&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt; 
              &lt;groupId&gt;javax.interceptor&lt;/groupId&gt; 
              &lt;artifactId&gt;javax.interceptor-api&lt;/artifactId&gt; 
              &lt;version&gt;1.2&lt;/version&gt; 
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-mail&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-jersey&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-web-services&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.mariadb.jdbc&lt;/groupId&gt;
              &lt;artifactId&gt;mariadb-java-client&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.projectlombok&lt;/groupId&gt;
              &lt;artifactId&gt;lombok&lt;/artifactId&gt;
              &lt;version&gt;1.18.2&lt;/version&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
              &lt;type&gt;jar&lt;/type&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;javax.annotation&lt;/groupId&gt;
              &lt;artifactId&gt;javax.annotation-api&lt;/artifactId&gt;
              &lt;version&gt;1.3.2&lt;/version&gt;
              &lt;type&gt;jar&lt;/type&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
              &lt;artifactId&gt;spring-security-core&lt;/artifactId&gt;
              &lt;version&gt;5.0.7.RELEASE&lt;/version&gt;
              &lt;type&gt;jar&lt;/type&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-thymeleaf&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-entitymanager&lt;/artifactId&gt;
              &lt;version&gt;5.3.4.Final&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-jpamodelgen&lt;/artifactId&gt;
              &lt;version&gt;5.3.4.Final&lt;/version&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-validator-cdi&lt;/artifactId&gt;
              &lt;version&gt;6.0.12.Final&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.jboss.aerogear&lt;/groupId&gt;
              &lt;artifactId&gt;aerogear-otp-java&lt;/artifactId&gt;
              &lt;version&gt;1.0.0&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;commons-codec&lt;/groupId&gt;
              &lt;artifactId&gt;commons-codec&lt;/artifactId&gt;
              &lt;version&gt;1.11&lt;/version&gt;
              &lt;type&gt;jar&lt;/type&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.google.zxing&lt;/groupId&gt;
              &lt;artifactId&gt;core&lt;/artifactId&gt;
              &lt;version&gt;3.3.0&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.google.zxing&lt;/groupId&gt;
              &lt;artifactId&gt;javase&lt;/artifactId&gt;
              &lt;version&gt;3.3.0&lt;/version&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;com.github.wvengen&lt;/groupId&gt;
                  &lt;artifactId&gt;proguard-maven-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.0.14&lt;/version&gt;
                  &lt;executions&gt;
                      &lt;execution&gt;
                          &lt;phase&gt;package&lt;/phase&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;proguard&lt;/goal&gt;
                          &lt;/goals&gt;
                      &lt;/execution&gt;
                  &lt;/executions&gt;
                  &lt;configuration&gt;
                      &lt;proguardVersion&gt;6.0.3&lt;/proguardVersion&gt;
                      &lt;options&gt;
                          &lt;option&gt;-target 1.8&lt;/option&gt;
                      &lt;/options&gt;
                      &lt;exclusions&gt;
                          &lt;!-- exclude the artifact  --&gt;
                          &lt;exclusion&gt;
                              &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
                              &lt;artifactId&gt;log4j-api&lt;/artifactId&gt;
                          &lt;/exclusion&gt;                                                    
                      &lt;/exclusions&gt;
                      &lt;proguardInclude&gt;${basedir}/src/main/resources/proguard.conf&lt;/proguardInclude&gt;
                      &lt;libs&gt;
                          &lt;lib&gt;${java.home}/lib/rt.jar&lt;/lib&gt;
                          &lt;lib&gt;${java.home}/lib/jce.jar&lt;/lib&gt;
                      &lt;/libs&gt;
                  &lt;/configuration&gt;
                  &lt;dependencies&gt;
                      &lt;dependency&gt;
                          &lt;groupId&gt;net.sf.proguard&lt;/groupId&gt;
                          &lt;artifactId&gt;proguard-base&lt;/artifactId&gt;
                          &lt;version&gt;6.0.3&lt;/version&gt;
                      &lt;/dependency&gt;
                  &lt;/dependencies&gt;
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
                  &lt;configuration&gt;
                      &lt;fork&gt;true&lt;/fork&gt;
                      &lt;executable&gt;true&lt;/executable&gt;
                  &lt;/configuration&gt;
                  &lt;executions&gt;
                      &lt;execution&gt;
                          &lt;id&gt;pre-integration-test&lt;/id&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;start&lt;/goal&gt;
                          &lt;/goals&gt;
                          &lt;configuration&gt;
                              &lt;skip&gt;${skip.it}&lt;/skip&gt;
                          &lt;/configuration&gt;
                      &lt;/execution&gt;
                      &lt;execution&gt;
                          &lt;id&gt;post-integration-test&lt;/id&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;stop&lt;/goal&gt;
                          &lt;/goals&gt;
                          &lt;configuration&gt;
                              &lt;skip&gt;${skip.it}&lt;/skip&gt;
                          &lt;/configuration&gt;
                      &lt;/execution&gt;
                      &lt;execution&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;repackage&lt;/goal&gt;
                          &lt;/goals&gt;
                          &lt;configuration&gt;
                             &lt;start-class&gt;org.springframework.boot.loader.JarLauncher&lt;/start-class&gt;
                          &lt;/configuration&gt;
                      &lt;/execution&gt;
                  &lt;/executions&gt;
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-failsafe-plugin&lt;/artifactId&gt;
                  &lt;configuration&gt;
                      &lt;skip&gt;${skip.it}&lt;/skip&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
  
          &lt;/plugins&gt;
      &lt;/build&gt;
  &lt;/project&gt;
  &lt;!-- https://mvnrepository.com/artifact/ --&gt;
  </code></pre>
  
  <p>My <code>proguard.conf</code>:</p>
  
  <pre><code>-dontnote
  -keepclasseswithmembers public class com.example.server.app.AppApplication {
      public static void main(java.lang.String[]);
  }
  </code></pre>