4 Replies Latest reply on Jan 30, 2004 3:25 PM by gretel

    Ear, war, sar => NoClassDefFoundError

    gretel Newbie

       

      "gretel" wrote:
      I'm having a lot of difficulty with classloading, specifically my web app can't resolve a class from a third-party jar file present in my ear. I get a NoClassDefFoundError from one of my (struts) action classes in the web app. No matter what I do I just can't seem to have the webapp find the third-party jar. Everything seems to deploy OK, problem arises when I try to log in to the web app.

      Here's the stack trace:
      2004-01-14 22:56:53,531 WARN [my.package.web.struts.action.BaseAction] my.package.web.struts.action.BaseAction: refreshUser
      java.lang.NoClassDefFoundError: util/data/time/Time^M
      at java.lang.Class.forName0(Native Method)^M
      at java.lang.Class.forName(Class.java:140)^M
      at my.package.web.struts.action.BaseAction.refreshUser(BaseAction.java:73)^M
      at my.package.web.struts.action.LoginAction.execute(LoginAction.java:119)^M
      at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:484)^M
      at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:274)^M
      at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)^M
      at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)^M
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)^M
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)^M
      at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:360)^M
      at org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:294)^M
      at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:558)^M
      at org.mortbay.http.HttpContext.handle(HttpContext.java:1714)^M
      at org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationContext.java:507)^M
      at org.mortbay.http.HttpContext.handle(HttpContext.java:1664)^M
      at org.mortbay.http.HttpServer.service(HttpServer.java:863)^M
      at org.jboss.jetty.Jetty.service(Jetty.java:460)^M
      at org.mortbay.http.HttpConnection.service(HttpConnection.java:775)^M
      at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:939)^M
      at org.mortbay.http.HttpConnection.handle(HttpConnection.java:792)^M
      at org.mortbay.http.SocketListener.handleConnection(SocketListener.java:201)^M
      at org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:289)^M
      at org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:455)^M


      I have an ear deployed on JBoss 3.2.0 as follows:

      myapp.ear
      - META-INF/MANIFEST.MF
      - META-INF/application.xml
      - META-INF/jboss-app.xml
      - lib/util.jar
      - myejb.jar
      ----- various ejb interfaces, bean classes, data classes, etc.
      ----- META-INF/MANIFEST.MF
      ----- META-INF/ejb-jar.xml
      ----- META-INF/jboss.xml
      ----- META-INF/jboss-cmp-jdbc.xml
      - myservice.sar
      ----- various common and service specific classes
      ----- META-INF/MANIFEST.MF
      ----- META-INF/jboss-service.xml
      - myweb.war
      ----- jsps, etc
      ----- META-INF/MANIFEST.MF
      ----- WEB-INF/classes/[various common and web-related classes]
      ----- WEB-INF/lib/[other jars]

      The class which can't be found resides in the util.jar in the lib directory of the ear. The MANIFEST files in myweb.war, ejb.jar and myservice.sar all have a classpath entry for the util.jar (including crlf) as follows:
      Class-Path: lib/util.jar

      The ear's application.xml:
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE application PUBLIC '-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN' 'http://java.sun.com/dtd/application_1\
      _3.dtd'>

      <application>
      <display-name>My App</display-name>
      <module>
      <web>
      <web-uri>myweb.war</web-uri>
      <context-root>/myweb</context-root>
      </web>
      </module>
      <module>
      <ejb>myejb.jar</ejb>
      </module>
      </application>

      The ear's jboss-app.xml (not sure if all three archives should be listed here?)
      <?xml version='1.0' encoding='UTF-8' ?>
      <!DOCTYPE jboss-app
      PUBLIC "-//JBoss//DTD J2EE Application 1.3V2//EN"
      "http://www.jboss.org/j2ee/dtd/jboss-app_3_2.dtd">

      <jboss-app>
      <loader-repository>user:ear=myapp.ear</loader-repository>
      <module>
      <service>myservice.sar</service>
      </module>
      <module>
      <service>myweb.war</service>
      </module>
      <module>
      <service>myejb.jar</service>
      </module>
      </jboss-app>

      The myservice.sar jboss-service.xml:
      <?xml version="1.0" encoding="UTF-8"?>

      <server>
      <mbean code="com.my.package.Service"
      name="user:service=MyService">
      </mbean>
      </server>

      Any ideas? I've read numerous postings on ear, war, jar classpath configuration and remain baffled.

      TIA





        • 1. Re: Ear, war, sar => NoClassDefFoundError
          Dmitry Sklyut Newbie

          Remove

          module
          service myweb.war /service
          module
          module
          service myejb.jar /service
          /module


          from your jboss-app.xml. service is only applicable to the sar archives.

          Also, Class-Path: in the metainf will only be looked at ear level (for the ejb.jar). Only include your utility lib at the ear level, do no include it in the sar or war. It should work.

          • 2. Re: Ear, war, sar => NoClassDefFoundError
            gretel Newbie

            Alas, no luck with your suggestion.

            I've gathered some info on the classloaders involved. When my sar is deployed the classloader is a jboss unified class loader. But the struts web app classloader is a mortbay classloader (suprising to me, I expected it to be a unified classloader as well given that its loaded from the ear).

            So I assume this mortbay classloader doesn't have access to the unified classloader classes, is this a correct assumption?

            What is really strange is that I can load my util.jar under the webapp's WEB-INF/lib directory and I can see it in the listed contents of the mortbay classloader. However the unobtainable class still can't be located from that jar file. Can anyone explain this and suggest a solution?

            classloader of sar:

            org.jboss.mx.loading.UnifiedClassLoader3@18c8aea{ url=file:/C:/apps/jboss3.2.0/server/default/tmp/deploy/server/default/deploy/myapp.ear/41.myapp.ear ,addedOrder=31}

            classloader of action class in war:

            org.mortbay.http.ContextLoader(file:/C:/WINNT/Temp/Jetty_0_0_0_0_8080__web/webapp/WEB-INF/classes/,file:/C:/WINN\
            T/Temp/Jetty_0_0_0_0_8080__web/webapp/WEB-INF/lib/commons-beanutils.jar,file:/C:/WINNT/Temp/Jetty_0_0_0_0_8080__web/webapp/WE\
            B-INF/lib/commons-collections.jar,file:/C:/WINNT/Temp/Jetty_0_0_0_0_8080__web/webapp/WEB-INF/lib/commons-digester.jar,file:/C\
            :/WINNT/Temp/Jetty_0_0_0_0_8080__web/webapp/WEB-INF/lib/commons-fileupload.jar,file:/C:/WINNT/Temp/Jetty_0_0_0_0_8080__web/we\
            bapp/WEB-INF/lib/commons-lang.jar,file:/C:/WINNT/Temp/Jetty_0_0_0_0_8080__web/webapp/WEB-INF/lib/commons-logging.jar,file:/C:\
            /WINNT/Temp/Jetty_0_0_0_0_8080__web/webapp/WEB-INF/lib/commons-validator.jar,file:/C:/WINNT/Temp/Jetty_0_0_0_0_8080__web/weba\
            pp/WEB-INF/lib/jakarta-oro.jar,file:/C:/WINNT/Temp/Jetty_0_0_0_0_8080__web/webapp/WEB-INF/lib/jfreechart-0.9.11.jar,file:/C:/\
            WINNT/Temp/Jetty_0_0_0_0_8080__web/webapp/WEB-INF/lib/struts-legacy.jar,file:/C:/WINNT/Temp/Jetty_0_0_0_0_8080__web/webapp/WE\
            B-INF/lib/struts.jar) / java.net.FactoryURLClassLoader@fd9b97, classpath, c:\apps\jboss-3.2.0\bin\run.jar;c:\j2sdk1.4.1_04\li\
            b\tools.jar)

            • 3. Re: Ear, war, sar => NoClassDefFoundError
              gretel Newbie

              Another thought. The location in the action class where the NoClassDefFoundError occurs is actually an instantiation of a class via Class.forName:

              Class clazz = Class.forName(myClass);

              As such, I'm wondering if there may be something special in this case with respect to class resolution?

              • 4. Re: Ear, war, sar => NoClassDefFoundError
                gretel Newbie

                Was a bug in release 3.2.0. Problem resolved by moving up to release 3.2.3. Argh, what a nightmare!