3 Replies Latest reply on Mar 10, 2008 5:05 PM by peterj

    5.0 beta3, war class scoping problem

    peterj

      JBossAS 5.0 beta3 has changed the scoping of classes within war files. Previously (as in 4.x.x, and even in beta3 as of last September), if a class in some other archive (such as an ear) attempted to instantiate a class packaged in a war, I got a exception. With beta3 (and beta4 pulled today after Adrian's classloader change - JBAS-5119), the class is successfully instantiated.

      At first I thought that the "useJBossWebLoader" property might now default to true, but is is still false.

      Is this new behavior intended, or are the new class loaders broke?

        • 1. Re: 5.0 beta3, war class scoping problem
          dimitris

          Peter, can you create a very simple example to demonstrate this?

          Any classloader changes made to AS5 were mostly to satisfy TCK requirements, however, we do use scoped deployments in the ear deployer in that particular setup.

           <property name="isolated">true</property>
           <property name="callByValue">true</property>
          


          • 2. Re: 5.0 beta3, war class scoping problem
            peterj

            Here are the test files:

            RouteServlet.java

            package peter.scope;
            import java.io.*;
            import javax.servlet.ServletException;
            import javax.servlet.http.*;
            public class RouteServlet extends HttpServlet {
             protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException,
             IOException {
             InEar ie = new InEar();
             String result = ie.route();
             PrintWriter out = resp.getWriter();
             out.print("<html><body><h2>" + result + "</h2></body></html>");
             }
             protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException,
             IOException {
             doGet(req, resp);
             }
            }


            InWar.java
            package peter.scope;
            public class InWar {
             public String route() {
             return "oops";
             }
            }


            InEar.java
            package peter.scope;
            public class InEar {
             public String route() {
             String result = null;
             try {
             result = callInWar();
             } catch (Throwable e) {
             result = "exception when calling InWar: " + e;
             }
             return result;
             }
             private String callInWar() {
             InWar id = new InWar();
             return id.route();
             }
            }


            application.xml
            <application>
             <display-name>Route</display-name>
             <module>
             <java>inear.jar</java>
             </module>
            </application>


            web.xml
            <?xml version="1.0" encoding="UTF-8"?>
            <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
             version="2.5"
            >
             <servlet>
             <servlet-name>Route</servlet-name>
             <servlet-class>peter.scope.RouteServlet</servlet-class>
             </servlet>
             <servlet-mapping>
             <servlet-name>Route</servlet-name>
             <url-pattern>/route</url-pattern>
             </servlet-mapping>
             <welcome-file-list>
             <welcome-file>route</welcome-file>
             </welcome-file-list>
            </web-app>


            Compile the three Java source files together. Then package the files as follows:

            inear.jar should contain:
            peter/scope/InEar.class

            inear.ear should contain:
            inear.jar
            META-INF/application.xml

            route.war should contain:
            WEB-INF/web.xml
            WEB-INF/classes/peter/scope/InWar.class
            WEB-INF/classes/peter/scope/RouteServlet.class

            Deploy inear.ear and route.war, point a browser at http://localhost:8080/route.

            When I do this on 5.0.0.Beta3, the browser displays:
            oops


            When I do this on 4.2.2.GA, the browser displays:
            exception when calling InWar: java.lang.NoClassDefFoundError: peter/scope/InWar



            • 3. Re: 5.0 beta3, war class scoping problem
              peterj

              This problem appears to have gotten worse - in beta4 class loader repository declarations are being ignored, making it impossible to do scoping. Or are class loader repositories going away, and if so, what is the replacement mechanism?