title: Could not find or load main class in fat/uber jar
body: <p>I have java project which has spring dependencies. I am building a jar file via ANT as shown below</p>
  
  <pre><code>&lt;jar jarfile="Test.jar"&gt;
      &lt;manifest&gt;
          &lt;attribute name="Main-Class" value="com.karthik.EntryPoint"/&gt;
      &lt;/manifest&gt; 
      &lt;fileset dir="${build.classes.dir}" includes="**" /&gt;
  &lt;/jar&gt;
  </code></pre>
  
  <p>When I run the command  <strong>java -jar Test.jar</strong>. I get an error as shown below</p>
  
  <pre><code>Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContext
          at java.lang.Class.getDeclaredMethods0(Native Method)
          at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
          at java.lang.Class.privateGetMethodRecursive(Unknown Source)
          at java.lang.Class.getMethod0(Unknown Source)
          at java.lang.Class.getMethod(Unknown Source)
          at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
          at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
  Caused by: java.lang.ClassNotFoundException: org.springframework.context.ApplicationContext
          at java.net.URLClassLoader.findClass(Unknown Source)
          at java.lang.ClassLoader.loadClass(Unknown Source)
          at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
          at java.lang.ClassLoader.loadClass(Unknown Source)
          ... 7 more
  </code></pre>
  
  <p>To resolve this, I created a fat/uber jar which has all spring dependencies as shown below :</p>
  
  <pre><code>&lt;jar jarfile="Test.jar"&gt;    
       &lt;zipgroupfileset dir="${build.dir}/lib" includes="spring*.jar" /&gt;  
  
       &lt;manifest&gt;
           &lt;attribute name="Main-Class" value="com.karthik.EntryPoint"/&gt;
       &lt;/manifest&gt;    
  
       &lt;fileset dir="${build.classes.dir}" includes="**" /&gt;
       &lt;fileset dir="${src.java.dir}" includes="**/*.java" /&gt;
  &lt;/jar&gt;
  </code></pre>
  
  <p>I can now see spring classes bundled in Test.jar.<br> But when I run the command <strong>java -jar Test.jar</strong>, I get an error as shown below</p>
  
  <pre><code>Error: Could not find or load main class com.karthik.EntryPoint
  </code></pre>
  
  <p>Why am I getting this error only in uber/fat jar and how do we resolve it?</p>