title: ClassNotFoundException when running a jar but not when running the app directly
body: <p>My app is facing a <code>NoClassDefFoundError</code> when trying to access external dependencies, but only when run as a jar.</p>
  
  <p>Using Intellij, I have a simple app with main class with some calls to external dependencies such as slf4j.</p>
  
  <pre><code>public class Main {
  private static final Logger logger = LoggerFactory.getLogger(Main.class);
       ///
      public static void main(String[] args) {
      logger.debug("start");
      }
  </code></pre>
  
  <p>}</p>
  
  <p>The <code>pom.xml</code> includes the relevant dependencies and the app is compiled successfully.</p>
  
  <p>When running the app from the intellij as regular application it is running with no problem.</p>
  
  <p>But when creating an executable jar out of it and trying to run it, it crashes and can't find external dependencies:</p>
  
  <pre><code> java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
    at com.example.Main.&lt;clinit&gt;(Main.java:18)
  Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
      at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
      ... 1 more
  Exception in thread "main" 
  Process finished with exit code 1
  </code></pre>
  
  <p>I added this to the pom to try to solve the problem, but it didn't help:</p>
  
  <pre><code>    &lt;build&gt;
      &lt;plugins&gt;
          &lt;plugin&gt;
              &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
              &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
              &lt;configuration&gt;
                  &lt;source&gt;1.8&lt;/source&gt;
                  &lt;target&gt;1.8&lt;/target&gt;
              &lt;/configuration&gt;
          &lt;/plugin&gt;
          &lt;plugin&gt;
              &lt;!-- Build an executable JAR --&gt;
              &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
              &lt;artifactId&gt;maven-jar-plugin&lt;/artifactId&gt;
              &lt;version&gt;3.0.2&lt;/version&gt;
              &lt;configuration&gt;
                  &lt;archive&gt;
                      &lt;manifest&gt;
                          &lt;addClasspath&gt;true&lt;/addClasspath&gt;
                          &lt;classpathPrefix&gt;lib/&lt;/classpathPrefix&gt;
                          &lt;mainClass&gt;com.example.Main&lt;/mainClass&gt;
                      &lt;/manifest&gt;
                  &lt;/archive&gt;
              &lt;/configuration&gt;
          &lt;/plugin&gt;
      &lt;/plugins&gt;
  &lt;/build&gt;
  </code></pre>
  
  <p>The manifest file is located in src/main/resources/META-INF/MANIFEST.MF:</p>
  
  <pre><code>Manifest-Version: 1.0
  Main-Class: com.example.Main
  </code></pre>