2 Replies Latest reply: Apr 19, 2012 7:57 AM by 931780 RSS

    Calling EJB 3.1 deployed in Glassfish 3.1 from  a web app in Tomcat7

      I have a EJB 3.1 bean deployed in Glassfish 3.1.1 server. I want to call this bean from a remote web client deployed in Tomcat 7. The EJB class and its remote interface is as follows ...

      Remote Interface -

      public interface MyEJBRemote
      public String sayHello();
      EJB Bean -

      public class MyEJB implements MyEJBRemote

      public String sayHello()
      return "Hello EJB Client. Hope everything worked just fine.";

      In the remote client I have the following code

      Properties props = new Properties();

      props.setProperty("java.naming.factory.initial", "com.sun.enterprise.naming.SerialInitContextFactory");
      props.setProperty("java.naming.factory.url.pkgs", "com.sun.enterprise.naming");
      props.setProperty("java.naming.factory.state", "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
      props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
      props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");

      InitialContext ic = new InitialContext(props);

      MyEJBRemote myEJBREmote = (MyEJBRemote)ic.lookup("java:global/MyEJB-1/MyEJB!com.dw.ejb.MyEJBRemote");
      Now the problem is with the last line of code. In Eclise this line of code is marked as error as the MyEJBRemote class is not there in the client project (the web app going to be deployed in tomcat 7). So where do I get the client jar generated from the deployed EJB to include in the client project ? Is there any way to generate this jar file.

      I tried using the glassfish command

      asadmin deploy generatermistubs retrieve . MyEJB.jar
      But glassfish didn't not generate any MyEJB-client.jar file. I tried a lot of times but without any success. I read up many forums. In one of them, it was mentioned that from EJB 3.1 glassfish does not generate the client stubs.

      So does that mean that one cannot use remote clients from EJB 3.1 in Glasssfish anymore ? Because the client project will never compile without the MyEJB-client.jar .
        • 1. Re: Calling EJB 3.1 deployed in Glassfish 3.1 from  a web app in Tomcat7
          You don't have to generate anything, you need the business interface class in your client application (MyEJBRemote in this case). One way to do that is to put the business interfaces in a separate jar and link that jar in both your client and server projects. The glassfish 3 FAQ documents the need to include the business interface class in your client application:


          Another option is to turn the EJB into a JAX-WS webservice, which can be as easy as only adding a few annotations to it. That way you don't need any additional dependencies at all; the only thing you need to do is generate the stub classes using the wsimport tool (also part of the JDK) for your client application. I'm not a huge fan of SOAP, but for internal use I find it less cumbersome and more portable than remote EJBs.

          I can't offer any more advice on the topic as I don't use Glassfish. For better help, I do advise you to ask in the Glassfish forum where you'll find more people that have been in the same boat you are.

          • 2. Re: Calling EJB 3.1 deployed in Glassfish 3.1 from  a web app in Tomcat7
            Thanks a lot for the quick and the correct reply. That just worked. Thanks again. :)