Note that there are some explanatory texts on larger screens.

plurals
  1. POSimple ant file for java "hello world"
    text
    copied!<p>I'm trying to run ant file and I keep getting the following error: </p> <pre><code>Exception in thread "main" java.lang.NoClassDefFoundError </code></pre> <p>My build.xml file contains this:</p> <pre><code>&lt;project name="Proj0" default="compile" basedir="."&gt; &lt;description&gt; Proj0 build file &lt;/description&gt; &lt;!-- global properties for this build file --&gt; &lt;property name="source.dir" location="src"/&gt; &lt;property name="build.dir" location="bin"/&gt; &lt;property name="doc.dir" location="doc"/&gt; &lt;property name="main.class" value="proj0.Proj0.java"/&gt; &lt;!-- set up some directories used by this project --&gt; &lt;target name="init" description="setup project directories"&gt; &lt;mkdir dir="${build.dir}"/&gt; &lt;mkdir dir="${doc.dir}"/&gt; &lt;/target&gt; &lt;!-- Compile the java code in ${src.dir} into ${build.dir} --&gt; &lt;target name="compile" depends="init" description="compile java sources"&gt; &lt;javac srcdir="${source.dir}" destdir="${build.dir}"/&gt; &lt;/target&gt; &lt;!-- execute the program with the fully qualified name in ${build.dir} --&gt; &lt;target name="run" description="run the project"&gt; &lt;java dir="${build.dir}" classname="${main.class}" fork="yes"&gt; &lt;arg line="${args}"/&gt; &lt;/java&gt; &lt;/target&gt; &lt;!-- Delete the build &amp; doc directories and Emacs backup (*~) files --&gt; &lt;target name="clean" description="tidy up the workspace"&gt; &lt;delete dir="${build.dir}"/&gt; &lt;delete dir="${doc.dir}"/&gt; &lt;delete&gt; &lt;fileset defaultexcludes="no" dir="${source.dir}" includes="**/*~"/&gt; &lt;/delete&gt; &lt;/target&gt; &lt;!-- Generate javadocs for current project into ${doc.dir} --&gt; &lt;target name="doc" depends="init" description="generate documentation"&gt; &lt;javadoc sourcepath="${source.dir}" destdir="${doc.dir}"/&gt; &lt;/target&gt; &lt;/project&gt; </code></pre> <p>How do I resolve this error?</p> <p><strong>EDIT: This is what my Proj0.java file and stack trace look like:</strong></p> <pre><code>package proj0; public class Proj0 { public static void main(String[] args) { System.out.println("Hello World"); } } </code></pre> <hr> <pre><code>Buildfile: build.xml run: [java] Exception in thread "main" java.lang.NoClassDefFoundError: proj0/Proj0 [java] Caused by: java.lang.ClassNotFoundException: proj0.Proj0 [java] at java.net.URLClassLoader$1.run(URLClassLoader.java:217) [java] at java.security.AccessController.doPrivileged(Native Method) [java] at java.net.URLClassLoader.findClass(URLClassLoader.java:205) [java] at java.lang.ClassLoader.loadClass(ClassLoader.java:321) [java] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294) [java] at java.lang.ClassLoader.loadClass(ClassLoader.java:266) [java] Could not find the main class: proj0.Proj0. Program will exit. [java] Java Result: 1 BUILD SUCCESSFUL Total time: 0 seconds </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload