Hi James,

It seems the documentation is not good enough .... :-) I'm updating it as
quickly as possible as it seems these classpaths issues are the major
problem with using Cactus ...

There are 2 parts in Cactus (i.e. 2 JVM involved), the client one (JUnit
test runner) and the server one (the test webapp located in your servlet
engine). You need to set correctly both classpaths.

On the client side you need in your classpath:
- commons-cactus.jar,
- your test classes
- your classes under test
- junit.jar
- servlet.jar

On the server side classpaths
- WEB-INF/lib/junit.jar
- WEB-INF/lib/cactus-commons.jar
- WEB-INF/classes/<your test classes>
- WEB-INF/classes/<your classes under test>

>From the stack trace, it seems you're missing either the
WEB-INF/classes/<your test classes> or any class used by TestExampleServlet
(such as junit.jar, your classes under test, ...).

Hope it helps
-Vincent


----- Original Message -----
From: "James Linder" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, August 15, 2001 12:07 AM
Subject: Cannot Instantiate Test class


Hi everyone,

I've been attempting to get cactus to work for a while now and I keep
coming up against the same problem.  I keep getting a
ClassNotFoundException on the testing class I have created.  It seems
like there is some classpath issue I am not seeing but I don't know what
it would be.  Here is what I have done:

1. I've created the classes ExampleServlet.java and
TestExampleServlet.java.  They are both in package 'test.example'.  (all
the servlet does is return a simple text string.  The test class simply
tells the servlet to execute it's doGet method.)

2. I know the servlet runs no problem (I've tested it and gotten the
expected response.)


3. I have put the cactus jar on the classpath.  I put the
cactus.properties file in the classpath.  JUnit is on the classpath.
I've set it all up within the same context too.  I must have cactus set
up nearly correctly because the cactus redirector servlet gets executed
on the server.  But when it gets to where it wants to instantiate the
TestExampleServlet class it bombs (the messages and stack traces are at
the bottom).

What could be going wrong?

Thanks alot,

James Linder


----------------------------------------
The Cactus redirector servlet gives the error:

1) testDoGet(test.example.TestExampleServlet)
javax.servlet.ServletException: Error instanciating class
[test.example.TestExampleServlet]
        at
org.apache.commons.cactus.server.ServletTestCaller.callTestMethod
(ServletTestCaller.java:107)
        at
org.apache.commons.cactus.server.ServletTestCaller.doTest(ServletTestCal
ler.java:200)
        at
org.apache.commons.cactus.server.ServletTestRedirector.doPost(ServletTes
tRedirector.java:149)
        at
org.apache.commons.cactus.server.ServletTestRedirector.doGet(ServletTest
Redirector.java:111)
        at
javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
        at
javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at
org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:405)
        at
org.apache.tomcat.core.Handler.service(Handler.java:287)
        at
org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
        at
org.apache.tomcat.core.ContextManager.internalService(ContextManager.jav
a:812)
        at
org.apache.tomcat.core.ContextManager.service(ContextManager.java:758)
        at
org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(H
ttpConnectionHandler.java:213)
        at
org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416
)
        at
org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:50
1)
        at java.lang.Thread.run(Thread.java:484)

----------------------------------------
  Tomcat gives the stacktrace:

java.lang.ClassNotFoundException:
test.example.TestExampleServlet
        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:297)
        at
sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:286)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:253)
        at
java.lang.ClassLoader.loadClassInternal(ClassLoader.java:313)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:120)
        at
org.apache.commons.cactus.server.ServletTestCaller.callTestMethod(Servle
tTestCaller.java:102)
        at
org.apache.commons.cactus.server.ServletTestCaller.doTest(ServletTestCal
ler.java:200)
        at
org.apache.commons.cactus.server.ServletTestRedirector.doPost(ServletTes
tRedirector.java:149)
        at
javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
        at
javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at
org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:405)
        at
org.apache.tomcat.core.Handler.service(Handler.java:287)
        at
org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
        at
org.apache.tomcat.core.ContextManager.internalService(ContextManager.jav
a:812)
        at
org.apache.tomcat.core.ContextManager.service(ContextManager.java:758)
        at
org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(H
ttpConnectionHandler.java:213)
        at
org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416
)
        at
org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:50
1)
        at java.lang.Thread.run(Thread.java:484)

----------------------------------------
The code for the TestExampleServlet.java class:

package test.example;

import org.apache.commons.cactus.*;
import org.apache.commons.cactus.util.*;

import junit.framework.*;

import javax.servlet.*;
import javax.servlet.http.*;
import java.net.*;

/**
 * To test the example servlet.
 */
public class TestExampleServlet extends ServletTestCase
{
    /** */
    public TestExampleServlet(String theName)
        { super(theName); }

    /** */
    public static Test suite()
        { return new TestSuite(TestExampleServlet.class); }

    /** */
    public static void main(String[] theArgs)
        { junit.textui.TestRunner.run(suite()); }

    /** */
    public void testDoGet() throws ServletException
    {
        ExampleServlet servlet = new ExampleServlet();
        servlet.doGet(request,response);
    }

    /** */
    public void testDoPost() throws ServletException
    {
        ExampleServlet servlet = new ExampleServlet();
        servlet.doGet(request,response);
    }

}


Reply via email to