Bug 44756 - Can't get a class name or stack trace for NoClassDefFoundError
Summary: Can't get a class name or stack trace for NoClassDefFoundError
Status: REOPENED
Alias: None
Product: Ant
Classification: Unclassified
Component: Core (show other bugs)
Version: 1.6.5
Hardware: PC Linux
: P2 major (vote)
Target Milestone: ---
Assignee: Ant Notifications List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-04-04 07:43 UTC by Kevin Gilpin
Modified: 2008-07-21 13:14 UTC (History)
0 users



Attachments
Ant's -v log of the junit task, also the contents of my ant/lib (5.21 KB, text/plain)
2008-04-04 07:43 UTC, Kevin Gilpin
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Kevin Gilpin 2008-04-04 07:43:50 UTC
Created attachment 21782 [details]
Ant's -v log of the junit task, also the contents of my ant/lib

I am running the JUnit ant task. The output of the task is:

    [junit] Exception in thread "main" java.lang.NoClassDefFoundError: 
    [junit] Tests FAILED

I've tried everything I can think of to get the class name or a stack trace without success, including:

* -v and -debug flags
* loading up a console and looking in the ClassLoader for duplicates of Ant classes (i'm not using anything suspect like weblogic.jar)
* running Ant in a debugger. I can't set a breakpoint for NoClassDefFoundError because it's occurring in a forked process

I'm at a loss to figure out what's going on. There may be a problem with my classpath but Ant doesn't give me enough information to figure out what it might be.

Same problem occurs with Ant 1.6.2.
Comment 1 Colm Smyth 2008-05-13 17:11:25 UTC
I agree it's not very obvious how to achieve this, but if you add an element
<formatter type="plain">
within your <junit> element, a text file will be created with the stack trace of your test case.

I wrote a basic test class XXXTest (no package) that referred to a missing class; the output went to a file TEST-XXXTest.txt as follows:

Testsuite: XXXTest
Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec
------------- Standard Error -----------------
This message went to syserr
------------- ---------------- ---------------

	Caused an ERROR
YYYTest
java.lang.NoClassDefFoundError: YYYTest
	at XXXTest.<clinit>(XXXTest.java:17)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:169)
Caused by: java.lang.ClassNotFoundException: YYYTest
	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 java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)


Note the NoClassDefFoundError. If however you run it on a class that doesn't exist (e.g. XXXTest1), you get a ClassNotFoundException:

Testsuite: XXXTest1
Tests run: 1, Failures: 0, Errors: 1, Time elapsed: 0 sec

	Caused an ERROR
XXXTest1
java.lang.ClassNotFoundException: XXXTest1
	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 java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:169)

I hope this helps.
Comment 2 Kevin Gilpin 2008-07-21 13:14:59 UTC
The problem is not when the test class itself does not exist, it appears to be when some class referenced by the test class does not exist. These tests work fine in my IDE. I can't figure out how to get Ant to tell me what class it can't find, nor how to attach a debugger to a running Ant JUnitTestRunner.