Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Exception in thread “main” java.lang.NoClassDefFoundError Caused by: java.lang.ClassNotFoundException: org.apache.tools.ant.Task

  1. #1
    Junior Member
    Join Date
    Jul 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Exception in thread “main” java.lang.NoClassDefFoundError Caused by: java.lang.ClassNotFoundException: org.apache.tools.ant.Task

    I am new to Java, although I have several years experience with other langs (e.g. C/C++ etc). I am trying to run an example program, which uses Ant for its build. I have struggled to get rid of the ClassNotFoundException being thrown for the last four days and despite trying various solutions posted elsewhere on the internet, I have been unable to solve the problem.

    I wonder if anyone on here can help.

    Here is the stack trace, (as well as my attempts to solve the problem):

    $ ./init-og-examples-db.sh
    ### Creating empty database
    Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/tools/ant/Task
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:212)
    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)
    Caused by: java.lang.ClassNotFoundException: org.apache.tools.ant.Task
    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)
    ... 11 more
    Could not find the main class: com.opengamma.util.test.DbTool. Program will exit.
    Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/tools/ant/Task
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:212)
    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)
    Caused by: java.lang.ClassNotFoundException: org.apache.tools.ant.Task
    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)
    ... 11 more
    Could not find the main class: com.opengamma.util.test.DbTool. Program will exit.
    ### Adding example data
    Exception in thread "main" java.lang.NoClassDefFoundError: com/opengamma/examples/tool/ExampleDatabasePopulator
    Caused by: java.lang.ClassNotFoundException: com.opengamma.examples.tool.ExampleDatabasePopulator
    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: com.opengamma.examples.tool.ExampleDatabasePopulator. Program will exit.
    ### Completed

    I am runing on Ubuntu 12.0.4 and my environment settings are as follows:


    echo $ANT_HOME
    /usr/local/apache-ant-1.9.1
    echo $JAVA_HOME
    /usr/lib/jvm/java-7-oracle/jre

    I have set my CLASSPATH as follows:

    export CLASSPATH=$CLASSPATH:/usr/local/apache-ant-1.9.1/etc:/usr/local/apache-ant-1.9.1/lib
    while (!(succeed == try()) );


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,606
    My Mood
    Hungover
    Thanks
    145
    Thanked 658 Times in 563 Posts

    Default Re: Exception in thread “main” java.lang.NoClassDefFoundError Caused by: java.lang.ClassNotFoundException: org.apache.tools.ant.Task

    I'm not convinced you can set the classpath to a directory like that. It has to be a jar or a class file. You should be able to use wildcard characters though:

    /usr/local/apache-ant-1.9.1/etc:/usr/local/apache-ant-1.9.1/lib/*.jar
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Jul 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Exception in thread “main” java.lang.NoClassDefFoundError Caused by: java.lang.ClassNotFoundException: org.apache.tools.ant.Task

    Quote Originally Posted by KevinWorkman View Post
    I'm not convinced you can set the classpath to a directory like that. It has to be a jar or a class file. You should be able to use wildcard characters though:

    /usr/local/apache-ant-1.9.1/etc:/usr/local/apache-ant-1.9.1/lib/*.jar

    Thanks Kevin, that seems to have done the trick. Hopefully, I should be able to carry on from here.
    while (!(succeed == try()) );

Similar Threads

  1. [SOLVED] Exception in thread "main" java.lang.NoClassDefFoundError
    By cppcppcpp in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 26th, 2012, 12:59 PM
  2. Replies: 3
    Last Post: March 7th, 2012, 05:54 AM
  3. Exception in thread "main" java.lang.NoClassDefFoundError
    By Scarice in forum Java Theory & Questions
    Replies: 25
    Last Post: July 4th, 2011, 11:02 PM
  4. Replies: 13
    Last Post: October 13th, 2010, 12:20 PM
  5. Replies: 1
    Last Post: October 25th, 2009, 12:54 PM