I was seeing this error after installing ant on CentOS 6.2 via yum:
$ ant Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/tools/ant/launch/Launcher Caused by: java.lang.ClassNotFoundException: org.apache.tools.ant.launch.Launcher at java.net.URLClassLoader$1.run(URLClassLoader.java:217) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:205) at java.lang.ClassLoader.loadClass(ClassLoader.java:321) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294) at java.lang.ClassLoader.loadClass(ClassLoader.java:266) Could not find the main class: org.apache.tools.ant.launch.Launcher. Program will exit.
Odd, generally yum packages work out of the box. The problem ends up being that ant can’t find ant-launcher.jar
The solution is to add the following to your .bashrc
export ANT_HOME=/usr/share/ant export JAVA_HOME=/usr/lib/jvm/java
Once you do that it should find the necessary jar and work just fine.
Hopefully that saves someone else the hassle of figuring this out.