this stuff can be _very_ hard to track down :-P
You're probably having a problem with the class-loader hierarchy and delegation model used by tomcat. Also note there's a difference between ClassNotFoundException (which is thrown when the class "really" couldn't be found) and NoClassDefFoundError (a linkage error).
For example, if the class Servlet1 is loaded by a parent class-loader (for example, you've put it in TOMCAT_HOME/shared/classes), but the class pkg1.AppClass1 is loaded by the web-app class-loader (you put it in WEB-INF/classes), you'll be unable to load pkg1.AppClass1 from Servlet1, and a NoClassDefFoundError will be thrown.
Hope this helps.
Mark wrote:
At 1/9/2003 12:02 AM, you wrote:I'm using Tomcat 4.1.12 with a working application that has a boatload of different packages. I'm successfully using BASIC authentication via the methods webRequest.setRedirectorName("ServletRedirectorSecure") and webRequest.setAuthentication( new BasicAuthentication("uid", "pwd")) if that makes any difference.Mark wrote:I have a server-side class loading problem, but not able to figure out why. Using Cactus I can run tests and access servlets just fine if the classes are all located under WEB-INF/classes directory, but I get NoClassDefFoundError if I try to access classes in a different package. This is a working application so I'm obviously not understanding something from the Cactus/classloader side of things. I've read the ClassPath HowTo and it only describes a WEB-INF/classes structure.Cactus should be able to load any classes that can be loaded by the web-application itself, because it's using the web-applications' class loader by default.
Given this directory structure:Weird.
/WEB-INF
|
/classes
|
Servlet1.class
TestClass1.class
/pkg1
|
AppClass1.class
I can run a test case where TestClass1 instantiates Servlet1, but if Servlet1 tries to instantiate pkg1.AppClass1, it's not found. This seems like it should be something very simple but I'm at a loss.
[Note that you shouldn't really use the "default package" (i.e. no package, classes directly under WEB-INF/classes in this case), except maybe in examples.]
Can you provide some more details, like the container you're using, maybe some log output, stack traces etc.?
I'm glad to hear this SHOULD work - I was concerned only classes located directly under WEB-INF/classes would get loaded. In my example, I put the 2 classes under WEB-INF/classes directory just to verify Cactus would work with the webapp in some regard (I was getting the NoClassDefFoundError right off the bat.
Following is the stacktrace. Everything works as expected until an attempt to load AppClass1 (and I've verified ../WEB-INF/classes/pkg1/AppClass1.class exists). The test is to verify a db connection can be made. I have to believe this is something simple I'm just not seeing for some reason.... Thanks. Mark
15:02:28,380 [main] DEBUG TestClass1 - Exception in test
java.lang.NoClassDefFoundError: pkg1/AppClass1
at Servlet1.getConnection(Servlet1.java:10)
at TestClass1.testDBConnection(TestClass1.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.apache.cactus.AbstractTestCase.runServerTest(AbstractTestCase.java:332)
[...]
-- Christopher Lenz /=/ cmlenz at gmx.de -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
