8 Replies Latest reply: Jul 12, 2012 7:14 AM by Periklis Douvitsas RSS

Class access / class visibility

Lucas Smith Newbie

Hi everyone!

 

I have a question about the following scenario.

 

I am using JBoss 5 AS. I deployed JAR module (with EJB) and WAR module. Servlet from WAR module uses EJB from JAR module.

I want to ask if classes that are deployed in different modules are visible to other modules. Or should I place them under default/lib folder?

  • 1. Re: Class access / class visibility
    Benjamin Seyinbour Expert

    Hi Lucas,

     

    You are using Jboss 5, and If you are deploying a *.war file, then put the ejb-module.jar in the  war-module/WEB-INF/lib and depoy.  

  • 2. Re: Class access / class visibility
    Lucas Smith Newbie

    I know that it can be done in such way. But I do not want to do it. I want to deploy such modules separately. Is there any solution?

  • 3. Re: Class access / class visibility
    Benjamin Seyinbour Expert

    Hi Marc,

     

    Another alternative, is to package the foo.war and foo.ejb in an foo.ear and deploy that  foo.ear, in which case you wouldn't need the foo.ejb in the foo.war. I am not sure how else classes that are deployed in different modules can be visible to other modules without linking their libraries in one form or another.

  • 4. Re: Class access / class visibility
    Periklis Douvitsas Newbie

    They are visible. You can have a client deployed in war that speaks with the EJB (jar). So you can have in the deploy directory two files, one war and one jar . You don't have to include them anywhere else. You can have stateless ejb that implement remote interfaces. From the client you call the ejb like that

     

            Context ctx = factory.getContext();       

            yourEJB yourContr = (yourEJB) ctx.lookup("blablaEJBBean/remote");

     

     

    Of course, when you are programmign in an IDE like netbeans in order your client project (servlet) to compile you have to add the ejb project, in order to find the classes but you dont need to put this into war-module/WEB-INF/lib.

     

    Do you have any error messages? 

  • 5. Re: Class access / class visibility
    Lucas Smith Newbie

    Periklis Douvitsas, you are right.

     

    Can you give me some explanation on which classes are visible to others?

  • 6. Re: Class access / class visibility
    Periklis Douvitsas Newbie

    here is an explanation how to call ejb3 using jboss 5

    http://javahowto.blogspot.gr/2007/11/simple-ejb-3-on-jboss-application.html

     

    what i do

    i create an interface and i include all the methods that i want to be visible to clients

     

    public interface ExampleEJB {

     

        public Sometype getDataById(Long Id);

     

        public List<IBla> getAllData();

     

    }

     

    i implement the class and the actual methods

    @Stateless

    public class ExampleEJBBean implements ExampleEJBRemote, ExampleEJBLocal {

     

        @PersistenceContext(name = "blaPU")

        EntityManager em;

        @Resource private SessionContext context;

     

        public ExampleEJBBean() {

        }

     

        public SometypegetDataById(Long Id) {

          

            //implement the method

            return sometype;

        }

     

         public List<IBla> getAllData(){

              ....

              return list;

         }

     

    }

     

    the local interface

    import javax.ejb.Local;

     

    /**

    *

    */

    @Local

    public interface ExampleEJBLocal extends ExampleEJB {

       

    }

     

    the remote

     

     

    import javax.ejb.Remote;

     

    /**

     

    */

    @Remote

    public interface ExampleEJBRemote extends ExampleEJB {

       

    }

     

     

    you can call the methods getDataById, getAllData (from the client) that you implement in ExampleEJBBean and you expose in  ExampleEJB interface.

     

    is this what you asking for?

    Hope this helps

  • 7. Re: Class access / class visibility
    Lucas Smith Newbie

    Thank you.

     

    The interface is needed because the Client needs it in classpath. So such interface can be placed in some kind of a library JAR.

     

    To sum up, it can be stated that beans from bean package A.jar are visible to those from B.jar package despite the fact that they are deployed independently. Am I right? But on the other hand there is something like application classloaders...

  • 8. Re: Class access / class visibility
    Periklis Douvitsas Newbie

    Hi

    yes, you are right.

     

    Maybe you can have a look at this webpage for classloader configuration in jboss

    https://community.jboss.org/wiki/ClassLoadingConfiguration

     

    Is this what you asking?

    Hope this helps