Friday, 13 March 2009

java.lang.ClassNotFoundException: org.apache.tools.ant.Main

This error should not be occuring when you install Ant out-of-the-box and run it. However, on the rare occasions it does occur - the solution is quite simple.



java.lang.ClassNotFoundException: org.apache.tools.ant.Main
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:244)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:67)



Take a look at the ANT_HOME/lib folder - and ensure that the ant.jar is in there and showing a size of 1MB or higher.

It is usually due to a corrupted version of ant.jar in the above path.