NoClassDefFoundError without any class name

Seagull picture Seagull · Jan 29, 2010 · Viewed 21.1k times · Source

I am trying to run a java task from ant. I am trying to run the "org.apache.tools.ant.launch.Launcher" class. I keep on getting the "NoClassDefFoundError" without any class name being specified. I am also getting a "ClassNotFoundException" along with that displaying a message "Could not find the main class: . Program will exit". Here's a snippet of the error

 [java] Exception in thread "main" java.lang.NoClassDefFoundError: 
 [java] Caused by: java.lang.ClassNotFoundException: 
 [java]  at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
 [java]  at java.security.AccessController.doPrivileged(Native Method)
 [java]  at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
 [java]  at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
 [java]  at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
 [java]  at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
 [java]  at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
 [java] Could not find the main class: .  Program will exit.
 [java] Java Result: 1

Now I am trying to run an ant class from an ant jar and i specifiy the classpath where this class file resides using the "classpathref" attribute, however I still get this message. I checked the ant jar to check the Manifest and the "main" class is specified properly (it's "org.apache.tools.ant.launch.Launcher") . I have exhausted all my resources. Please help ! ! !

ps: My environment is Eclipse on Ubuntu 9.04

Answer

kritzikratzi picture kritzikratzi · May 22, 2010

Most likely your classpath is misconfigured.

At a minimum the CLASSPATH should include:

  • ant.jar and ant-launcher.jar
  • jars/classes for your XML parser
  • the JDK's required jar/zip files

(from the ant manual)

Also you seem to be relaunching ant in the current directory (executing the same build.xml). Maybe you'll want to set the "dir" property.