Ant: Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/tools/ant/launch/Launcher

Swathi EP picture Swathi EP · Nov 18, 2010 · Viewed 34.7k times · Source

I've installed ubuntu 10.10 in my system and installed ant with the following command: sudo apt-get install ant

Now, ant is visible in the share folder, so I've tried to run the ant command in terminal, but it gives me this error:

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:202)
       at java.security.AccessController.doPrivileged(Native Method)
       at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
       at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: org.apache.tools.ant.launch.Launcher.  Program will exit.

Then I set these again:

JAVA_HOME="/usr/lib/jvm/java-6-sun-1.6.0.22/"
ANT_HOME="/usr/share/ant/"
PATH="/usr/share/ant/bin/"

Now it is giving me the same error but with one different line at starting:

/usr/share/ant/bin/ant: 92: uname: not found
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:202)
       at java.security.AccessController.doPrivileged(Native Method)
       at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
       at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
       at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: org.apache.tools.ant.launch.Launcher.  Program will exit.

Answer

Mr Lou picture Mr Lou · May 10, 2011

try the following:

JAVA_HOME="/usr/lib/jvm/java-6-sun"
ANT_HOME="/usr/share/ant" # do not add "bin" at the end of the path**
PATH="$ANT_HOME/bin:$PATH"