title: Apache Ant java.lang.NoClassDefFoundError
body: <p>Possible Answer <a href="https://stackoverflow.com/questions/4214979/ant-exception-in-thread-main-java-lang-noclassdeffounderror-org-apache-tools">Stack Over flow question</a></p>
  <p>My problem is same as described in the above thread.I went throught the solution and its not working.
  <strong>ant compile</strong> working perfectly. <strong>ant jar</strong> saying cant load the main class</p>
  <pre><code>Exception in thread &quot;main&quot; java.lang.NoClassDefFoundError: LoadServer (wrong name: org/module/loader/LoadServer)
      at java.lang.ClassLoader.defineClass1(Native Method)
      at java.lang.ClassLoader.defineClass(ClassLoader.java:791)
      at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
      at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
      at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
      at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
      at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
      at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
  </code></pre>
  <p>I did the following in commnad line</p>
  <pre><code>JAVA_HOME=&quot;/usr/local/java/jdk1.7.0_21&quot;
  ANT_HOME=&quot;/usr/share/ant/&quot;
  PATH=&quot;$ANT_HOME/bin:$PATH&quot;
  </code></pre>
  <p>Morever if I start a new terminal and type <strong>echo$JAVA_HOME</strong> its showing the above result but <strong>echo$ANT_HOME</strong> is giving null.</p>
  <p><a href="https://docs.google.com/file/d/0Bz8w_lUmpqFaUllWWlZvQ3d6YUU/edit?usp=sharing" rel="nofollow noreferrer">here is a screen shot</a></p>
  <p>Initial Error</p>
  <pre><code>     &lt;project name=&quot;Raxa-4&quot; basedir=&quot;.&quot; default=&quot;main&quot;&gt;
  
      &lt;property name=&quot;src.dir&quot;      value=&quot;src&quot;/&gt;
      &lt;property name=&quot;prop.dir&quot;     value=&quot;properties&quot;/&gt;
      &lt;property name=&quot;resource.dir&quot; value=&quot;resource&quot;/&gt;
      &lt;property name=&quot;lib.dir&quot;      value=&quot;lib&quot;/&gt;
      &lt;property name=&quot;build.dir&quot;    value=&quot;build&quot;/&gt;
      &lt;property name=&quot;classes.dir&quot;  value=&quot;${build.dir}/classes&quot;/&gt;
      &lt;property name=&quot;jar.dir&quot;      value=&quot;${build.dir}/jar&quot;/&gt;
      &lt;property name=&quot;main-class&quot;   value=&quot;org.raxa.module.loader.LoadServer&quot;/&gt;
  
      &lt;path id=&quot;classpath&quot;&gt;
              &lt;fileset dir=&quot;${lib.dir}&quot; includes=&quot;**/*.jar&quot;/&gt;
      &lt;/path&gt;
  
      &lt;target name=&quot;clean&quot;&gt;
          &lt;delete dir=&quot;${build.dir}&quot;/&gt;
      &lt;/target&gt;
  
      &lt;target name=&quot;compile&quot;&gt;
          &lt;mkdir dir=&quot;${classes.dir}&quot;/&gt;
          &lt;javac srcdir=&quot;${src.dir}&quot; destdir=&quot;${classes.dir}&quot; classpathref=&quot;classpath&quot; includeantruntime=&quot;false&quot; /&gt;
          &lt;copy todir=&quot;${classes.dir}&quot;&gt;
              &lt;fileset dir=&quot;${resource.dir}&quot; excludes=&quot;**/*.java&quot;/&gt;
              &lt;fileset dir=&quot;${prop.dir}&quot; excludes=&quot;**/*.java&quot;/&gt;
          &lt;/copy&gt;
      &lt;/target&gt;
  
     &lt;target name=&quot;jar&quot; depends=&quot;compile&quot;&gt;
          &lt;mkdir dir=&quot;${jar.dir}&quot;/&gt;
           &lt;classpath&gt;
              &lt;path refid=&quot;classpath&quot;/&gt;
              &lt;path location=&quot;${jar.dir}/${ant.project.name}.jar&quot;/&gt;
          &lt;/classpath&gt;
          &lt;/jar&gt;
      &lt;/target&gt;
  
  
      &lt;target name=&quot;run&quot; depends=&quot;jar&quot;&gt;
          &lt;java jar=&quot;${jar.dir}/${ant.project.name}.jar&quot; fork=&quot;true&quot;/&gt;
  
      &lt;/target&gt;
  
      &lt;target name=&quot;clean-build&quot; depends=&quot;clean,jar&quot;/&gt;
  
      &lt;target name=&quot;main&quot; depends=&quot;clean,run&quot;/&gt;
  
  &lt;/project&gt;
  </code></pre>
  <p>Edited:
  </p>
  <pre><code>    &lt;property name=&quot;src.dir&quot;      value=&quot;src&quot;/&gt;
      &lt;property name=&quot;prop.dir&quot;     value=&quot;properties&quot;/&gt;
      &lt;property name=&quot;resource.dir&quot; value=&quot;resource&quot;/&gt;
      &lt;property name=&quot;lib.dir&quot;      value=&quot;lib&quot;/&gt;
      &lt;property name=&quot;build.dir&quot;    value=&quot;build&quot;/&gt;
      &lt;property name=&quot;classes.dir&quot;  value=&quot;${build.dir}/classes&quot;/&gt;
      &lt;property name=&quot;jar.dir&quot;      value=&quot;${build.dir}/jar&quot;/&gt;
      &lt;property name=&quot;main-class&quot;   value=&quot;org.raxa.module.loader.LoadServer&quot;/&gt;
  
      &lt;path id=&quot;classpath&quot;&gt;
              &lt;fileset dir=&quot;${lib.dir}&quot; includes=&quot;**/*.jar&quot;/&gt;
      &lt;/path&gt;
  
      &lt;target name=&quot;clean&quot;&gt;
          &lt;delete dir=&quot;${build.dir}&quot;/&gt;
      &lt;/target&gt;
  
      &lt;target name=&quot;compile&quot;&gt;
          &lt;mkdir dir=&quot;${classes.dir}&quot;/&gt;
          &lt;javac srcdir=&quot;${src.dir}&quot; destdir=&quot;${classes.dir}&quot; classpathref=&quot;classpath&quot; includeantruntime=&quot;false&quot; /&gt;
          &lt;copy todir=&quot;${classes.dir}&quot;&gt;
              &lt;fileset dir=&quot;${resource.dir}&quot; excludes=&quot;**/*.java&quot;/&gt;
              &lt;fileset dir=&quot;${prop.dir}&quot; excludes=&quot;**/*.java&quot;/&gt;
          &lt;/copy&gt;
      &lt;/target&gt;
  
     &lt;target name=&quot;jar&quot; depends=&quot;compile&quot;&gt;
          &lt;mkdir dir=&quot;${jar.dir}&quot;/&gt;
          &lt;jar destfile=&quot;${jar.dir}/${ant.project.name}.jar&quot; basedir=&quot;${classes.dir}&quot;&gt;
              &lt;manifest&gt;
                  &lt;attribute name=&quot;Main-Class&quot; value=&quot;${main-class}&quot;/&gt;
              &lt;/manifest&gt;
          &lt;/jar&gt;
      &lt;/target&gt;
  
  
      &lt;target name=&quot;run&quot; depends=&quot;jar&quot;&gt;
          &lt;java jar=&quot;${jar.dir}/${ant.project.name}.jar&quot; fork=&quot;true&quot;/&gt;
          &lt;classpath&gt;
              &lt;path refid=&quot;classpath&quot;/&gt;
              &lt;path location=&quot;${jar.dir}/${ant.project.name}.jar&quot;/&gt;
          &lt;/classpath&gt;
      &lt;/target&gt;
  
      &lt;target name=&quot;clean-build&quot; depends=&quot;clean,jar&quot;/&gt;
  
      &lt;target name=&quot;main&quot; depends=&quot;clean,run&quot;/&gt;
  
  &lt;/project&gt;
  </code></pre>
  <p><strong>NEW ERROR</strong> on ant run</p>
  <p>run:</p>
  <pre><code>[java] Exception in thread &quot;main&quot; java.lang.NoClassDefFoundError: org/apache/log4j/Logger
   [java]     at org.raxa.module.scheduler.TimeSetter.&lt;clinit&gt;(Unknown Source)
   [java]     at org.raxa.module.loader.LoadServer.main(Unknown Source)
   [java] Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Logger
   [java]     at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
   [java]     at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
   [java]     at java.security.AccessController.doPrivileged(Native Method)
   [java]     at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
   [java]     at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
   [java]     at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
   [java]     at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
   [java]     ... 2 more
   [java] Java Result: 1
  
  BUILD FAILED
  /home/atul/Documents/workspace2/Raxa-4/build.xml:41: Problem: failed to create task or type classpath
  Cause: The name is undefined.
  Action: Check the spelling.
  Action: Check that any custom tasks/types have been declared.
  Action: Check that any &lt;presetdef&gt;/&lt;macrodef&gt; declarations have taken pla
  </code></pre>