title: How to solve a NoClassDefFoundError caused by ClassNotFoundException?
body: <p>I'm trying to make an extension for <a href="http://www.bluej.org" rel="nofollow noreferrer">BlueJ</a> (this is a free <code>Java Development Environment</code> designed for beginners). The Extension should help the first year students in our school.
  The extension has to be a JAR file, that I have to place in a folder where <code>BlueJ</code> can load it at <code>runtime</code>. My already written extension can be loaded from there and it works without any problem.</p>
  
  <p>Now to the reason, for this question:
  I want to integrate <a href="http://checkstyle.sourceforge.net" rel="nofollow noreferrer">checkstyle</a> (this is a development tool to help programmers write Java code that adheres to a coding standard.) into my extension. So I put the <code>checkstyle jar</code> within my project and tried to use this library inside my code. If I now generate a jar and copy my extension into the <code>BlueJ</code> folder and start <code>BlueJ</code> out of eclipse I get the following error:</p>
  
  <blockquote>
    <p>java.lang.NoClassDefFoundError:
    com/puppycrawl/tools/checkstyle/api/CheckstyleException   at
    ch.ntb.sir.ntbbluejextension.NtbBlueJExtension.startup(NtbBlueJExtension.java:79)
      at
    bluej.extmgr.ExtensionWrapper.safeStartup(ExtensionWrapper.java:533)
      at
    bluej.extmgr.ExtensionWrapper.newExtension(ExtensionWrapper.java:209)
      at
    bluej.extmgr.ExtensionsManager.loadDirectoryExtensions(ExtensionsManager.java:164)
      at
    bluej.extmgr.ExtensionsManager.loadExtensions(ExtensionsManager.java:100)
      at
    bluej.extmgr.ExtensionsManager.getInstance(ExtensionsManager.java:61)
      at bluej.Main.(Main.java:101)     at
    sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      at
    sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
      at
    sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
      at java.lang.Class.newInstance(Class.java:442)  at
    bluej.Boot.bootBluej(Boot.java:348)   at bluej.Boot.main(Boot.java:175)
        Caused by: java.lang.ClassNotFoundException: com.puppycrawl.tools.checkstyle.api.CheckstyleException  at
    java.net.URLClassLoader.findClass(URLClassLoader.java:381)    at
    java.lang.ClassLoader.loadClass(ClassLoader.java:424)     at
    java.lang.ClassLoader.loadClass(ClassLoader.java:357)     ... 14 more</p>
  </blockquote>
  
  <p>At <code>NtbBlueJExtension.java:79</code> I make this initialization:</p>
  
  <pre><code>`codeAnalysisHandler = new CodeAnalysisHandler();`
  </code></pre>
  
  <p>Inside the <code>CodeAnalysisHandler</code> class I have imports from the <code>checkstyle libraries</code>:</p>
  
  <pre><code>import com.puppycrawl.tools.checkstyle.Checker;
  import com.puppycrawl.tools.checkstyle.ConfigurationLoader;
  import com.puppycrawl.tools.checkstyle.PropertiesExpander;
  import com.puppycrawl.tools.checkstyle.TreeWalker;
  import com.puppycrawl.tools.checkstyle.api.AuditEvent;
  import com.puppycrawl.tools.checkstyle.api.AuditListener;
  import com.puppycrawl.tools.checkstyle.api.CheckstyleException;
  import com.puppycrawl.tools.checkstyle.api.Configuration;
  </code></pre>
  
  <p>My first though is, that there I should find the cause of my problem? But then I have no idea what to search and how to solve it.</p>
  
  <p>I've added the jar in my project properties in eclipse.
  The Jar is inside the project structure in my <code>lib</code> folder. <code>BlueJ</code> had no problem to load the <code>bluejext.jar</code> from the "lib" folder. The <code>bluejext.jar</code> comes from <code>BlueJ</code> and is required to write an extension for BlueJ.
  I have this manifest file:</p>
  
  <pre><code>Manifest-Version: 1.0
  Main-Class: ch.ntb.sir.ntbbluejextension.NtbBlueJExtension
  Class-Path: lib/bluejext.jar lib/checkstyle-all.jar
  </code></pre>
  
  <p>I tried to google it, but found mostly information about how difficult it is to find the reason. </p>
  
  <p><strong>EDIT 1:</strong>
  I unzipped my JAR file to look, if the <code>checkstyle-all.jar</code> is really inside my extension and there I found a file <code>.classpath</code>:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;classpath&gt;
      &lt;classpathentry kind="src" path="src"/&gt;
      &lt;classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/&gt;
      &lt;classpathentry kind="lib" path="lib/bluejext.jar"/&gt;
      &lt;classpathentry kind="lib" path="lib/checkstyle-all.jar"/&gt;
      &lt;classpathentry kind="output" path="bin"/&gt;
  &lt;/classpath&gt;
  </code></pre>
  
  <p><strong>SOLUTION:</strong>
  Use Eclipse Kepler with the <a href="http://fjep.sourceforge.net" rel="nofollow noreferrer">fat jar plugin</a> (Neon was to new for the plugin) and export the project with ´Build Fat Jar´. After that the ´java.lang.ClassNotFoundException´ didn't appear anymore.</p>
  
  <p>Thanks for your help.</p>