1 2 Previous Next 18 Replies Latest reply on Nov 3, 2002 2:28 AM by Michael Angelo Libio

    Struts: NoClassDefFoundError

    Dirk Laessig Newbie

      Hi,

      I'm using struts in jboss. My war contains
      the struts.jar in the WEB-INF/lib folder and
      also another jar file with my derived
      ActionForm/Action classes in WEB-INF/lib. I
      try to access my ActionForm class in a JSP
      page. But I get a NoClassDefFoundError when
      I access one of my classes. The following
      lines:

      <%= org.apache.struts.action.Action.class %>
      <%= org.apache.struts.action.ActionForm.class %>
      <%= com.camelot.web.CourseForm.class %>

      generate the following output ....

      class org.apache.struts.action.Action
      class org.apache.struts.action.ActionForm


      Error: 500
      Location: /catalog/course.jsp
      Internal Servlet Error:

      javax.servlet.ServletException: org/apache/struts/action/ActionForm
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:508)
      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.java:812)
      at org.apache.tomcat.core.ContextManager.service(ContextManager.java:758)
      at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:213)
      at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
      at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:501)
      at java.lang.Thread.run(Thread.java:484)

      Root cause:
      java.lang.NoClassDefFoundError: org/apache/struts/action/ActionForm
      at java.lang.ClassLoader.defineClass0(Native Method)
      at java.lang.ClassLoader.defineClass(ClassLoader.java:486)
      at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:111)
      at java.net.URLClassLoader.defineClass(URLClassLoader.java:248)
      at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
      at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:297)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:253)
      at org.apache.tomcat.loader.AdaptiveClassLoader.loadClass(AdaptiveClassLoader.java:446)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:253)
      at org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:136)
      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 _0002fcourse_0002ejspcourse_jsp_19.class$(_0002fcourse_0002ejspcourse_jsp_19.java:15)
      at _0002fcourse_0002ejspcourse_jsp_19._jspService(_0002fcourse_0002ejspcourse_jsp_19.java:120)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:119)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      at org.apache.jasper.servlet.JspServlet$JspCountedServlet.service(JspServlet.java:130)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:282)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:429)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:500)
      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.java:812)
      at org.apache.tomcat.core.ContextManager.service(ContextManager.java:758)
      at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:213)
      at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
      at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:501)
      at java.lang.Thread.run(Thread.java:484)


      Any idea?

      Thanks,
      Dirk

        • 1. Re: Struts: NoClassDefFoundError
          Dirk Laessig Newbie

          This error occures only, when I deploy the war file
          within an ear file. If the war file is deployed
          seperatly, it works.

          Dirk

          • 2. Re: Struts: NoClassDefFoundError
            Daniel Johnson Newbie

            I am having this same problem. Have you found a resolution yet? My stacktrace is a little different:

            2001-10-18 11:12:09 - path="/star" :action: Processing a GET for /menu
            2001-10-18 11:12:09 - path="/star" :action: Looking for Action instance for class com.pubco.security.beans.MenuAction
            2001-10-18 11:12:09 - path="/star" :action: Double checking for Action instance already there
            2001-10-18 11:12:09 - path="/star" :action: Creating new Action instance
            2001-10-18 11:12:09 - path="/star" :action: Error creating Action instance for path '/menu', class name 'com.pubco.secur
            ity.beans.MenuAction' - java.lang.NoClassDefFoundError: org/apache/struts/action/Action
            at java.lang.ClassLoader.defineClass0(Native Method)
            at java.lang.ClassLoader.defineClass(Unknown Source)
            at java.security.SecureClassLoader.defineClass(Unknown Source)
            at java.net.URLClassLoader.defineClass(Unknown Source)
            at java.net.URLClassLoader.access$100(Unknown Source)
            at java.net.URLClassLoader$1.run(Unknown Source)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at org.apache.tomcat.loader.AdaptiveClassLoader.loadClass(AdaptiveClassLoader.java:446)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClassInternal(Unknown Source)
            at java.lang.Class.forName0(Native Method)
            at java.lang.Class.forName(Unknown Source)
            at org.apache.struts.action.ActionServlet.processActionCreate(ActionServlet.java:1630)
            at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1576)
            at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:491)
            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.java:812)
            at org.apache.tomcat.core.ContextManager.service(ContextManager.java:758)
            at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:213)
            at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
            at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:501)
            at java.lang.Thread.run(Unknown Source)

            • 3. Re: Struts: NoClassDefFoundError
              Aaron Smith Newbie

              I've encountered the same problem, but only when the WAR is deployed within the EAR. It's not necessarily something specific to JBoss either, because the same problem occurs with the Reference Implementation.

              The problem seems to be related to the ClassLoader, but I haven't found the problem or a work around yet.

              Cheers,
              Aaron.

              • 4. Re: Struts: NoClassDefFoundError
                Andrej Newbie

                Hello,

                it is a ClassLoader issue. Check out the following article (in two parts):

                http://www.onjava.com/lpt/a//onjava/2001/06/26/ejb.html

                In 2 words, you must use add a "Class-Path" to the MANIFEST.MF of your .ear (note: EAR). In your case, you need to add a reference to "struts.jar".

                I hope this helps.

                Andrej

                • 5. Re: Struts: NoClassDefFoundError
                  Peet Denny Newbie

                  Hi,
                  Is this the only way to get the classpath issue sorted with struts, without using a seperate ejb-jar and war?

                  I've got the following lines in my manifest (the ear):

                  Manifest-Version: 1.0
                  Created-By: ant1.4
                  Class-Path: struts.jar

                  and struts.jar is in my war file (included in the ear)

                  but I'm still getting this error:

                  2001-11-20 09:38:05 - path="/wallpaper" :action: Looking for Action instance for class denny.wallpaper.jsptools.CreateSchoolAction
                  2001-11-20 09:38:05 - path="/wallpaper" :action: Double checking for Action instance already there
                  2001-11-20 09:38:05 - path="/wallpaper" :action: Creating new Action instance
                  2001-11-20 09:38:05 - path="/wallpaper" :action: Error creating Action instance for path '/CreateSchool', class name 'denny.wallpaper.jsptools.CreateSchoolAction' - java.lang.NoClassDefFoundError: org/apache/struts/action/Action
                  at java.lang.ClassLoader.defineClass0(Native Method)..... etc....

                  The next thing I'm going to try is putting my struts.jar directly into the ear.
                  Any tips?
                  Cheers
                  Peet

                  • 6. Re: Struts: NoClassDefFoundError
                    Verdi March Newbie

                    another work around: extract struts.jar and put all
                    contents under /WEB-INF/classes

                    Dirty, but works (hopefully)

                    • 7. Re: Struts: NoClassDefFoundError
                      Peet Denny Newbie

                      Cheers for this,
                      but gaaa! it doesn't work even though I put my classes straight in to the WEB-INF/classes dir.
                      It all works if I deploy the ejb-jar and war seperately, but not if I put them together into an ear.

                      Is there anywhere else I can put it?
                      Actually, I'm using the JBoss 2.2.2/Tomcat3.2.2 bundle, so maybe there were some classloader issues with that which have been ironed out.

                      Why doesn't it work to just put struts.jar in the <jboss-instDir>lib/ext directory?. Do the struts classloaders also look in the same place for my specific Action classes?
                      Cheers
                      Peet

                      • 8. Re: Struts: NoClassDefFoundError
                        Verdi March Newbie

                        Hm, dunno why? but I remember I once struck with this same problem too,
                        but solved when I extract struts.jar into /WEB-INF/classes.

                        Maybe it's because I only used struts' custom tag?

                        Have you put also /META-INF in struts.jar (which contains manifest.mf,
                        taglib.tld and /tlds? I put struts' /META-INF under /WEB-INF/classes too,
                        here's the stcuructure:[pre]WEB-INF
                        |
                        |---classes
                        |
                        |--mycompany
                        | |
                        | |-** --> my class
                        |
                        |--org (root of org.apache.struts....)
                        |--META-INF
                        |
                        |-tlds (subdir)
                        |-MANIFEST.MF
                        |-taglib.tld[/pre]Hope it works...

                        • 9. Re: Struts: NoClassDefFoundError
                          Peet Denny Newbie

                          Thanks again.
                          I finally got it working using the jars & the extensions classpath. (solution details below)
                          Out of professional courtesy though, I gave your solution a whirl, and...STILL couldn't get it to work. Wierd, what OS/JBoss version are you using?

                          Anyway, after a day of working on it, I got it working after reading this article mentioned in one of the other threads:
                          http://java.sun.com/j2se/1.3/docs/guide/extensions/spec.html

                          Contrary to what was mentioned earlier, mine only worked if I put the manifest w/ the classpath in the *war* (not ear), and struts.jar in my ear. How the classpath works, since the war is inside the ear, beats me, but here's my structure:
                          Ear file contains:
                          ejb-jar
                          war
                          struts.jar
                          war file contains:
                          my app classes (in the WEB-INF/classes dir
                          a MANIFEST.MF in the META-INF directory
                          all my web app stuff
                          MANIFEST.MF contains the following lines:
                          Manifest-Version: 1.0
                          Created-By: ant1.4
                          Class-Path: struts.jar

                          Anyway, this all works for me (Jboss2.4.3/Tomcat3.2.3) on win2000 w/ jdk 1.3, hope it'll help someone else save a day of hair-rending.

                          What I'm still not sure of is how the Class-Path reference works. If the struts.jar, and the war are both in the ear, what kind of scope is going on if the Class-Path: struts.jar works?


                          Righto.

                          • 10. Re: Struts: NoClassDefFoundError
                            Sascha Dechert Newbie

                            Hi.

                            i have a similar problem.

                            i am using JBoss-2.4.1_Tomcat-3.2.3 on win2k.

                            i have a servlet and some jsp's. i am just using the servlet to hold the functions which are called from the jsp's. but to get the binary outputstream i have to do a post directly on the servlet.

                            while doin the post on the servlet i got a ClassNotFoundException:

                            [Default] javax.naming.CommunicationException. Root exception is
                            [Default] java.lang.ClassNotFoundException: de.procar.ecaros1.lcm.LCMHomeInterface
                            [Default] at org.apache.tomcat.loader.AdaptiveClassLoader.loadClass(AdaptiveClassLoader.java:524)
                            [Default]
                            [Default] at java.lang.ClassLoader.loadClass(Unknown Source)
                            [Default]
                            [Default] at java.lang.ClassLoader.loadClassInternal(Unknown Source)
                            [Default]
                            [Default] at java.lang.Class.forName0(Native Method)
                            [Default]
                            [Default] at java.lang.Class.forName(Unknown Source)
                            [Default]
                            [Default] at sun.rmi.server.MarshalInputStream.resolveProxyClass(Unknown Source)
                            [Default]
                            [Default] at java.io.ObjectInputStream.inputProxyClassDescriptor(Unknown Source)
                            [Default]
                            [Default] at java.io.ObjectInputStream.readObject(Unknown Source)
                            [Default]
                            [Default] at java.io.ObjectInputStream.readObject(Unknown Source)
                            [Default]
                            [Default] at java.io.ObjectInputStream.inputObject(Unknown Source)
                            [Default]
                            [Default] at java.io.ObjectInputStream.readObject(Unknown Source)
                            [Default]
                            [Default] at java.io.ObjectInputStream.readObject(Unknown Source)
                            [Default]
                            [Default] at java.rmi.MarshalledObject.get(Unknown Source)
                            [Default]
                            [Default] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:353)
                            [Default]
                            [Default] at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:333)
                            [Default]
                            [Default] at javax.naming.InitialContext.lookup(Unknown Source)
                            [Default]
                            [Default] at de.procar.ecaros1.lcm.LCMServlet.(LCMServlet.java:38)
                            [Default]
                            [Default] at java.lang.Class.newInstance0(Native Method)
                            [Default]
                            [Default] at java.lang.Class.newInstance(Unknown Source)
                            [Default]
                            [Default] at org.apache.tomcat.core.ServletWrapper.loadServlet(ServletWrapper.java:268)
                            [Default]
                            [Default] at org.apache.tomcat.core.ServletWrapper.init(ServletWrapper.java:289)
                            [Default]
                            [Default] at org.apache.tomcat.core.Handler.service(Handler.java:254)
                            [Default]
                            [Default] at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
                            [Default]
                            [Default] at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:812)
                            [Default]
                            [Default] at org.apache.tomcat.core.ContextManager.service(ContextManager.java:758)
                            [Default]
                            [Default] at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:213)
                            [Default]
                            [Default] at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
                            [Default]
                            [Default] at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:501)
                            [Default]
                            [Default] at java.lang.Thread.run(Unknown Source)
                            [Default]
                            [Default] java.lang.NullPointerException
                            [Default] at de.procar.ecaros1.lcm.LCMServlet.loadLicence(LCMServlet.java:54)
                            [Default]
                            [Default] at de.procar.ecaros1.lcm.LCMServlet.doPost(LCMServlet.java:285)
                            [Default]
                            [Default] at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
                            [Default]
                            [Default] at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
                            [Default]
                            [Default] at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:405)
                            [Default]
                            [Default] at org.apache.tomcat.core.Handler.service(Handler.java:287)
                            [Default]
                            [Default] at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
                            [Default]
                            [Default] at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:812)
                            [Default]
                            [Default] at org.apache.tomcat.core.ContextManager.service(ContextManager.java:758)
                            [Default]
                            [Default] at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:213)
                            [Default]
                            [Default] at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
                            [Default]
                            [Default] at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:501)
                            [Default]
                            [Default] at java.lang.Thread.run(Unknown Source)
                            [Default]
                            [Default] java.lang.NullPointerException
                            [Default] at de.procar.ecaros1.lcm.LCMServlet.createXmlFile(LCMServlet.java:319)
                            [Default]
                            [Default] at de.procar.ecaros1.lcm.LCMServlet.doPost(LCMServlet.java:287)
                            [Default]
                            [Default] at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
                            [Default]
                            [Default] at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
                            [Default]
                            [Default] at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:405)
                            [Default]
                            [Default] at org.apache.tomcat.core.Handler.service(Handler.java:287)
                            [Default]
                            [Default] at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
                            [Default]
                            [Default] at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:812)
                            [Default]
                            [Default] at org.apache.tomcat.core.ContextManager.service(ContextManager.java:758)
                            [Default]
                            [Default] at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:213)
                            [Default]
                            [Default] at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
                            [Default]
                            [Default] at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:501)
                            [Default]
                            [Default] at java.lang.Thread.run(Unknown Source)
                            [Default]
                            [Default] java.lang.NullPointerException
                            [Default] at org.apache.tomcat.core.BufferedServletOutputStream.write(BufferedServletOutputStream.java:158)
                            [Default]
                            [Default] at de.procar.ecaros1.lcm.LCMServlet.doPost(LCMServlet.java:290)
                            [Default]
                            [Default] at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
                            [Default]
                            [Default] at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
                            [Default]
                            [Default] at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:405)
                            [Default]
                            [Default] at org.apache.tomcat.core.Handler.service(Handler.java:287)
                            [Default]
                            [Default] at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
                            [Default]
                            [Default] at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:812)
                            [Default]
                            [Default] at org.apache.tomcat.core.ContextManager.service(ContextManager.java:758)
                            [Default]
                            [Default] at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:213)
                            [Default]
                            [Default] at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
                            [Default]
                            [Default] at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:501)
                            [Default]
                            [Default] at java.lang.Thread.run(Unknown Source)

                            my constructor methode looks like:

                            try{
                            Hashtable map = new Hashtable();
                            map.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
                            map.put("java.naming.provider.url", "jnp://localhost:1099");
                            map.put("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");

                            InitialContext jndiContext = new InitialContext(map);
                            Object ref = jndiContext.lookup("lcmbean/LCMBean"); <-- here the error occurs

                            LCMHomeInterface home = (LCMHomeInterface) PortableRemoteObject.narrow(ref, LCMHomeInterface.class);

                            remoteInterface = home.create();
                            }
                            catch(Exception e){
                            e.printStackTrace();
                            }

                            does anyone have an idea why this occurs? Or has an idea how to get the binary outputstream with out the direct post on the servlet?

                            Sorry for the long pastings.

                            Greets and thanks
                            Sascha

                            • 11. Re: Struts: NoClassDefFoundError
                              john mcdonald Newbie

                              I also only found success using the method detailed by hraun.

                              Nothing else worked!

                              Thanks hraun.

                              • 12. Re: Struts: NoClassDefFoundError
                                Klaus Thiele Newbie

                                JBoss2.4.1 seems a little bit broken in this case.

                                with 2.4.3 there are absolute no problems with struts in an ear/war.

                                • 13. Re: Struts: NoClassDefFoundError
                                  john mcdonald Newbie

                                  Have you tried stuts with jboss 2.3.1. I coudn't get it to work for the life of me, until I took hrauns' config advice.

                                  If I package the struts.jar inside the lib dir of my war it simply cannot find the struts classes.

                                  Am I missing something?

                                  -john:m

                                  • 14. Re: Struts: NoClassDefFoundError
                                    john mcdonald Newbie

                                    I meant version 2.4.1, not 2.3.1.

                                    Sorry.

                                    1 2 Previous Next