java.lang.NoClassDefFoundError: org/apache/cactus/ServletTestCase

By W.ZH Dec 28 2010



When I try to run my test case through servlet of ServletTestRunner from the cactus’s war file. i face this exception:

java.lang.NoClassDefFoundError: org/apache/cactus/ServletTestCase


In fact it is very hard to find the reason fro this kind of things. We should explain how this cactus runs by class loader, then you can know what may cause this:

WEB-INF/classes CL --> WEB-INF/lib CL --> system CL

You see, the cactus WEB-INF/classes in fact should contain your test cases classes, those u write to inherit the ServletTestCase.

and all cactus related jar should be put into the WEB-INF/lib.

to make your test cases can run,you normally also has alot other jars put into the ear file top layer, bu they are outside the WEB-INF.

So there are three place u need to check:

1. WEB-INF/classes has all the test cases class.

2. WEB-INF/lib has all the test case support jar lib files.

3. Your top layer(outside the WEB-INF), do not has any test cases class. You may need to unzip all your jars to look for them.

What error I made is N0. 3!

like this :


After u find the reason, I think you know how to fix this error!