Q:

How to look up an object of a class

There is an application ABC which dependency is on an ejb module 'XYZ' but both are deployed & running on different server machine.
ABC deployed on JBoss AS & IP address is 192.108.1.1
XYZ deployed on JBOss As & IP address is 192.108.1.2
in XYZ ejb module, there is a xyzService class which access db and populates the data into a bean class, please see below
@Stateless(mappedName = "ejb/xyzService")
@TransactionManagement(TransactionManagementType.BEAN)
public class XyzService extends XyzPersistenceService implements xyzRemote, xyzLocal {

     public List<xyzBean> fetchDataFromDB (List<String> idList) throws Exception
        {
            List<xyzBean> detailList = null;
            try {
                // gets data from DB and populate into a bean class i.e. xyzBean

            } catch (Exception e) {
                new myExceptionClass("error", e);
            }
            return detailList;
        }
    }

//Bean class

public class xyzBean{
    String Id;
    String name;
    // getter-setter here
}

Now i want,
1. lookup the object of service class of XYZ module
2. invoke the method
3. gets the list of bean class
Could you please guide me how to do that, while i am bit confused how to start doing this from my ABC application ? 

A:

This example is geared towards connecting to the XYZ bean, but you could easily use it with a little adjustment for the ABC bean. Anyway, here is how you can lookup your xyzService.

Explicitly
By @EJB annotation
By ejb-ref

Explicitly
// Lookup the EJB from JNDI
InitialContext ctx = new InitialContext();
xyzRemote remoteobj = (xyzRemote)ctx.lookup("ejb/xyzService");

By annotation
@EJB (mappedName="ejb/xyzService")
private xyzRemote remoteobj;

With annotation the container injects an instance of the remote EJB bean through DI.
By ejb-ref
In your client class, add the below code. This is only a
InitialContext ctx = new InitialContext();
xyzRemote remoteobj = (xyzRemote) ctx.lookup("java:comp/env/ejb/xyzService");

As for configuring your client's InitialContext, you'll need a jndi.properties file
### JBossNS properties
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.provider.url=jnp://192.108.1.2:1099
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces

