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.

10 comments:

  1. Very helpful! Thanks!

    ReplyDelete
  2. I had the same issue.
    ant was in my PATH
    but ANT_HOME was not set

    ReplyDelete
  3. Yes Richard - that too. Thanks.

    ReplyDelete
  4. yes i find it , it showing a size1.22 mb but i still have the problem :s

    ReplyDelete
  5. I have the ant.jar in the mentioned path, it showing a size of 1.49 mb but i still have the same problem.

    ReplyDelete
  6. It is because ant-launcher.jar is not there in classpath

    ReplyDelete
  7. Very succinct and good answer

    ReplyDelete