Hi Vincent
You seem to be missing at least two things here:
1. In your original post you said:
> When I access the servlet, I get a ClassNotFoundException on a
> JUnit class. So far it is normal ...
> When I debugged it, I have actually found that the error was
> happening when ServletTestRedirector was instancianting
> MyProxyClass (which does _not_ make use of JUnit) and before
> it was calling its method.
This does not look right. You say MyProxyClass does not make
use of JUnit, but it *does*. This is the line that causes it to:
> testInstance = (ServletTestCase)constructor.newInstance(new Object[] {
theMethod });
You see here you are explicitly referencing ServletTestCase which
extends junit.framework.TestCase, this introduces the dependency.
2. You seem to be assuming that NoClassDefFoundError extends
Exception, but it doesn't. If you want to catch a
NoClassDefFoundError you'll have to catch it directly, or one of
its superclasses (java.lang.LinkageError, java.lang.Error, or
java.lang.Throwable). This is why "I would have thought here"
never gets printed out:
> } catch (Exception e) {
> log("I would have thought here");
> }
As an aside, I'm not sure what you are trying to achieve here?
You don't have junit.jar in your classpath, and then you're say
you get this strange error. The details aside, isn't that what
you'd expect :-)? Even if you hadn't referenced ServletTestCase
directly, you still wouldn't have been able to instantiate it
using reflection without junit.jar in the classpath. What are
you really trying to achieve?
-- Andrew