XML : Ant Script Java Error: Could not find or load main class

I've been working on a homework assignment which should be relatively easy, build an Ant script. The script is supposed to compile, create a jar, and then run the jar with the following commands:

  ant compile  ant jar  ant run    

Compiling and creating the jar doesn't throw any errors, however with run I keep getting an error stating: Could not find or load main class ant.HelloAnt. My code is listed below, I would appreciate any and all help and would be forever greatful.

HelloAnt.java

  package ant;    public class HelloAnt {      public static void main(String[] args) {          System.out.println("Hello Ant");      }  }    

build.xml

  <target name="clean">      <delete dir="build"/>  </target>    <target name ="compile">      <mkdir dir="build/classes"/>      <javac srcdir="src" destdir="build/classes"/>  </target>    <target name ="jar">      <mkdir dir="build/jar"/>      <jar destfile="build/jar/HelloAnt.jar" basedir="build/classes">          <manifest>              <attribute name ="Main-Class" value="ant.HelloAnt"/>          </manifest>      </jar>  </target>    <target name ="run">      <java jar="build/jar/HelloAnt.jar" fork="true"/>  </target>    

No comments:

Post a Comment