2 Replies Latest reply: Nov 4, 2011 11:39 AM by 897916 RSS

    Looking up remote EJBs from a Java SE application

    665820
      I have a Java EE EAR that contains several EJBs (remote and webservices). I have some batch programs that are meant to invoke the remote EJBs to do some work. Within my bundles I have a few, so let's say there's a library "interface" that defines all of the shared objects, "remote-services" that contains the implementation of the remote ejbs (the interfaces for them are in the interface library) and the batches are in the file system somewhere. My EAR file has in the lib directory interface.jar, and remote-services.jar is defined as a module in my application.xml.

      Whenever I try to run my batch, I get a ClassNotFoundException thrown back stating that it can't find a class that is present in my interface.jar; but seems to be coming from the application server. Do I need to structure my deployment in a different way? If so, how?
        • 1. Re: Looking up remote EJBs from a Java SE application
          René van Wijk
          Some info on packaging your application can be found here: http://middlewaremagic.com/weblogic/?p=6725

          An example to call an EJB remotely is given here: http://middlewaremagic.com/weblogic/?p=6193
          • 2. Re: Looking up remote EJBs from a Java SE application
            897916
            Hi here is my working code in the real world.

            @Remote
            public interface MasterService
            {
            .......
            }

            @Stateful(name = "MasterServiceBean", mappedName = "ejb/MasterServiceBean")
            public class MasterServiceBean implements MasterService
            {
            .........
            }

            In client side,

            MasterService masterService = null;
                      try
                      {
                           Context ctx = getInitialContext("t3://localhost:7001", "weblogic", "Welcome1");
                           InitialContext ctx = new InitialContext();
                           Object obj = ctx.lookup("ejb.MasterServiceBean#ca.ns.gov.sns.phaseone.sfsb.MasterService");
            #the JNDI name is mappedName + full qualified EJB interface name
                           masterService = (MasterService)obj;
                      } catch (NamingException e) {
                           e.printStackTrace();
                      }

            It should work in your J2SE.