You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-user@jakarta.apache.org by "Varma, Nitesh" <ni...@tvworks.com> on 2006/05/04 23:24:51 UTC

NoClassDefFoundError - can't find the servlet class under test

I'm trying to test one of our servlets running on JBoss 4.0.3 with cactus 1.7.2

 

The problem is that my Cactus TestCase can't instantiate the servlet to test. My cactified ear file contains the following:

 

-          application jar file

-          application war file

-          cactus.war file

 

cactus.war file contains all my test classes. I used the following to cactify my ear file:

 

        <cactifyear srcfile="${cactify.dir}/${project.name}.ear" destfile="${cactify.dir}/${project.name}-cactified.ear">

              <cactuswar context="/${test.context}" version="2.3">

                  <classes dir="${cactify.dir}/test/classes">

                      <include name="**/*Test.class"/>

                  </classes>

              </cactuswar>

        </cactifyear>

 

This generates cactus.war with the following structure:

WEB-INF\classes\com\liberate\vod\web\test\ MyServletTest.class

WEB-INF\lib +

-          aspectrjt-1.2.1.jar

-          cactus-1.7.1.jar

-          commons-logging-1.0.4.jar

-          junit-3.8.1.jar

WEB-INF\web.xml

 

It seems like the cactus.war is not seeing classes under [application.war] because of class loader issue. But my understanding is that application
classes shouldn't be included in cactus.war.

 

I'm probably missing something basic. But what, I don't know! Any hint will be appreciated. 

 

The server-side stack trace is as follows:

 

14:13:19,951 INFO  [STDOUT] java.lang.NoClassDefFoundError: com/liberate/vod/web/TVPV7FrontServlet

14:13:19,952 INFO  [STDOUT]     at com.liberate.vod.web.test. MyServletTest.testGetRootFolder(MyServletTest.java:59)

14:13:19,952 INFO  [STDOUT]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

14:13:19,952 INFO  [STDOUT]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

14:13:19,952 INFO  [STDOUT]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

14:13:19,952 INFO  [STDOUT]     at java.lang.reflect.Method.invoke(Method.java:585)

14:13:19,953 INFO  [STDOUT]     at junit.framework.TestCase.runTest(TestCase.java:154)

14:13:19,953 INFO  [STDOUT]     at junit.framework.TestCase.runBare(TestCase.java:127)

14:13:19,953 INFO  [STDOUT]     at org.apache.cactus.internal.AbstractCactusTestCase.runBareServer(AbstractCactusTestCase.java:153)

 

The following is my test class:

 

public class MyServletTest extends ServletTestCase {

 

            public MyServletTest (String arg0) {

                        super(arg0);

            }

 

    public MyServletTest ()

    {

        super();

    }

 

    public MyServletTest (String arg0, Test arg1)

    {

        super(arg0, arg1);

    }

 

            protected void setUp() throws Exception {

                        super.setUp();

            }

 

            protected void tearDown() throws Exception {

                        super.tearDown();

            }

            

            public void beginGetFolderContent(WebRequest theRequest)

            {

                // Set up HTTP related parameters

                theRequest.setURL("localhost:8080", "/vod", null, null, null);

                theRequest.addParameter(GET_FOLDER_CONTENT_QUERY, "", WebRequest.POST_METHOD);

            }

 

            public void testGetRootFolder() throws Throwable

            {

                        TVPV7FrontServlet servlet = null;

                        try {

                                    servlet = new TVPV7FrontServlet();

                        } catch (Throwable t) {

                                    t.printStackTrace();

                                    throw t;

                        }

                

                // Call method to test

                servlet.doPost(this.request, this.response);

 

                // Perform some server side asserts

            }

 

            public void endXXX(WebResponse theResponse)

            {

                        assertNotNull(theResponse.getText());

                        assertEquals(HttpServletResponse.SC_OK, theResponse.getStatusCode());

            }

}


Re: NoClassDefFoundError - can't find the servlet class under test

Posted by Kazuhito SUGURI <su...@lab.ntt.co.jp>.
Hi,

You may already solved the problem.

In article <03...@tvpmail.ad.liberate.com>,
Thu, 4 May 2006 17:24:51 -0400,
"Varma, Nitesh" <ni...@tvworks.com> wrote: 
nitesh_varma>  My cactified ear file contains the following:
nitesh_varma> 
nitesh_varma> -          application jar file
nitesh_varma> 
nitesh_varma> -          application war file
nitesh_varma> 
nitesh_varma> -          cactus.war file
nitesh_varma> 
[snip]
nitesh_varma> It seems like the cactus.war is not seeing classes under
nitesh_varma> [application.war] because of class loader issue.

I think it's the class-loader issue as you mentioned.


nitesh_varma> But my understanding is that application classes shouldn't
nitesh_varma> be included in cactus.war.

I think you should cactify application.war in your ear file
instead of cactus.war.

Separation of the production archive and the test archive may be important,
however, that does not mean that application classes and test classes
shouldn't be archived into the same war-archive.
In fact, cactifywar creates such test archive from an existing production
archive.

Regards,
----
Kazuhito SUGURI