1 Reply Latest reply on May 3, 2007 4:48 PM by alrubinger

    package protected interfaces

    dunks80

      So playing around today I came across something I found strange and I was hoping someone might be able to explain why the following behavior occurs.

      In my example I have 4 classes..



      //an ejb3 interface

      package test;
      
      import javax.ejb.Local;
      
      @Local
      interface Test
      {
       String test(TestUser testuser);
      
      }
      


      //an ejb3 implementation class
      package test;
      
      import javax.ejb.Stateless;
      import org.jboss.annotation.ejb.LocalBinding;
      import org.jboss.annotation.ejb.Management;
      import org.jboss.annotation.ejb.Service;
      
      @Stateless(name = "Test")
      @LocalBinding(jndiBinding = "Test/local")
      public class TestImpl implements Test
      {
       public String test(TestUser testUser)
       {
      
       return testUser.sayHello();
       }
      }
      


      //a simple pojo
      package test;
      
      import javax.naming.InitialContext;
      
      public class TestUser
      {
       public String test()
       {
       try
       {
       InitialContext context=new InitialContext();
       Test test=(Test)context.lookup("Test/local");
       return test.test(this);
       }
       catch(Exception e)
       {
       e.printStackTrace();
       }
       return null;
      
       }
      
       protected String sayHello()
       {
       return "Hello";
       }
      }
      


      //and a simple servlet
      package servlet;
      
      import java.io.IOException;
      import javax.servlet.ServletException;
      import javax.servlet.http.HttpServlet;
      import javax.servlet.http.HttpServletRequest;
      import javax.servlet.http.HttpServletResponse;
      import test.TestUser;
      
      public class TestServlet extends HttpServlet
      {
      
       @Override
       protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
       {
       TestUser test=new TestUser();
       response.getWriter().write(test.test());
      
       }
      
      }
      

      All classes except the servlet are in the same package.

      My first deployment looks like this
      
      
      ${jboss.home}/server/myserver/deploy/
       test-core.jar
       test.Test
       test.TestUser
      
      ${jboss.home}/server/myserver/deploy/
       test-ejb.jar
       test.TestImpl
      
      ${jboss.home}/server/myserver/deploy/
       test.war
       WEB-INF/classes
       servlet.TestServlet
      

      If i run this the deployment fails with this error
      java.lang.ClassNotFoundException: Unexpected error during load of: test.TestImpl, msg=class test.TestImpl cannot access its superinterface test.Test
      


      I thought this was strange because they are in the same package just different archives...but then I thought ok maybe this isn't legal.

      So then i took all those same components and deployed them in an ear...and everything worked!

      As one last test I removed the ejb3 annotations and just made the ejb classes pojos still deployed serperately as described above (not in a .ear). Also instead of a jndi lookup in the TestUser pojo I did a direct instantiation of the TestImpl class. They worked that way as well.

      So I guess I'm wondering why I can't do a direct deployment of ejb3 implementation classes separately from their interfaces if the interfaces are package protected?

      Thanks

        • 1. Re: package protected interfaces
          alrubinger

          Is it possible that the container is deploying your test-ejb.jar before your test-core.jar? If so, it'll be attempting to deploy your EJB3 beans before the required libraries are in place.

          If this is the case, try:

          1) Placing test-core.jar into $JBOSS_HOME/server/[instanceName]/lib (assuming it has no deployable units in it, just classes needed as libs)

          - or -

          2) Ensuring the order of deployment is correct (maybe by using the PrefixDeployer and prepending your JAR names with "0-", 1-...N-, etc). This is configured at the bottom of $JBOSS_HOME/server/[instanceName]/conf/jboss-service.xml

          - or -

          3) Stick to the EAR deployment, and ensure that each of your modules are declared correctly in META-INF/application.xml

          S,
          ALR