4 Replies Latest reply on Jan 21, 2016 2:17 PM by Gary Aitken

    ejb deployment, ClassNotFound in war inside ear, specified in web.xml

    Gary Aitken Newbie

      alert: newbie migrating old code...

       

      I've got some old (pre ejb 3.0) ejbs I'm migrating to 9.0

      After getting rid of *LocalHome, *RemoteHome, fixing jndi lookups,

      then attempting to deploy,

      I got the message about "Empty name segment is not allowed for security-domain"

      After setting the security-domain to "other" I now get the following when trying to enable the app:

       

      2016-01-19 13:48:05,291 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-5) MSC000001:

        Failed to start service jboss.undertow.deployment.default-server.default-host./my-stuff-context-root.UndertowDeploymentInfoService:

          org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./my-stuff-context-root.Und

      ertowDeploymentInfoService: java.lang.ClassNotFoundException:

            org.mystuff.MyServlet from [Module "deployment.my_ear.ear.my_war.war:main" from Service Module Loader]

       

      The org.mystuff.MyServlet.class exists in my_war.war in my_ear.ear

        my_ear.ear

          ...

          my_war.war

            ...

            WEB-INF

              web.xml

            org

              mystuff

                MyServlet.class

            ...

       

      The error is coming as a result of the .war's WEB-INF/web.xml containing:

        <servlet>

          <description>my service</description>

          <servlet-name>MyServlet</servlet-name>

          <servlet-class>org.mystuff.MyServlet</servlet-class>

        </servlet>

       

      What am I missing?

        • 1. Re: ejb deployment, ClassNotFound in war inside ear, specified in web.xml
          Jay SenSharma Master

          Your class "org.mystuff.MyServlet"   should be actually placed inside the   "my_ear.ear/my_war.war/WEB-INF/classes/org/mystuff/MyServlet"

           

          Inside WAR the classes should be either placed inside the "WEB-INF/lib" (as a JAR file),  OR  inside the "WEB-INF/classes"  if not packaged inside a JAR.

           

           

          This is according to the Servlet Specification: http://download.oracle.com/otn-pub/jcp/servlet-3_1-fr-eval-spec/servlet-3_1-final.pdf

          Specification Section "10.5 Directory Structure"


          The contents of the WEB-INF directory are:

          ■ The /WEB-INF/web.xml deployment descriptor.

          ■ The /WEB-INF/classes/ directory for servlet and utility classes. The classes in this directory must be available to the application class loader.

          ■ The /WEB-INF/lib/*.jar area for Java Archive files. These files contain servlets, beans, static resources and JSPs packaged in a JAR file and other utility classes useful to the Web application. The Web application class loader must be able to load classes from any of these archive files.

           

           

          Regards

          Jay SenSharma

          • 2. Re: ejb deployment, ClassNotFound in war inside ear, specified in web.xml
            Gary Aitken Newbie

            Thank you!

            I had seen conflicting descriptions of where the class files went.

             

            That gets past one problem but now I have another;

            search comes up with everything except what I need...

             

            This .ear contains libraries used in more than one place.

            The ear file spec enumerates 4 kinds of .jar files which may be in an ear:

              Web modules (.war)

              EJB modules (.jar)

              Resource Adapter Modules (.rar)

              Application Client Modules (.jar)

            None of these are libraries.

              For example, if I have a foo.jar that contains things needed by the

              web module classes and the EJBs, how do I package them in the .ear?

             

            I have classes and libraries sitting in a .jar file in the "lib" subdirectory of the .ear:

              my_ear.ear

               lib

                 my_libraries.jar

                   org

                     mystuff

                       SomeClass.class

                   lib

                     one_of_my_libs.jar

                my_war.war

            Classes in one_of_my_libs.jar are not found when loading the .war file that is in the .ear

            • 3. Re: ejb deployment, ClassNotFound in war inside ear, specified in web.xml
              James Livingston Apprentice

              You can put jar files in the 'lib' directory of the EAR. You cannot however nest jars inside other jars, which is what your tree seems to indicate.

              • 4. Re: ejb deployment, ClassNotFound in war inside ear, specified in web.xml
                Gary Aitken Newbie

                Thanks.

                You can put jar files in the 'lib' directory of the EAR. You cannot however nest jars inside other jars, which is what your tree seems to indicate.

                I'm not sure that's true.  According to the spec 8.2.1 (Bundled Libraries):

                1.  "A JAR format file ... may reference a .jar file or directory by naming the referenced .jar file or directory in a Class-Path header in the referencing JAR file's Manifest file."

                2.  "... These libraries may reference other libraries, either bundled with the application or installed separately, using any of the techniques describes herein."

                However, in my case the problem was that the .war file referenced a class in a jar inside a top-level jar, so it wouldn't do the recursive search in the class loader.  I think if it referenced a class in the top-level jar, and that class referenced a class in a jar packaged in the top-level jar's lib subdirectory, it would have worked.  But I haven't needed that yet...

                Thanks again