1

我的项目结构将是这样的:

->WebSphere 应用服务器 (WAS)

----->耳朵

-------->EJB 模块

-------->EJB客户端

----->战争

-------->Web服务服务器

我如何从该 WAR 调用或使用 EJB?

当战争在耳边时,我之前尝试过调用 EJB:

public SomeEJBServiceClassBusiness getBusinessClass() throws RemoteException {

    SomeEJBServiceClassBusiness SomeEJBServiceClassBusiness = null;
    try {
        Hashtable env = new Hashtable();
        env.put(Context.INITIAL_CONTEXT_FACTORY,
                "com.ibm.websphere.naming.WsnInitialContextFactory");
        env.put(Context.PROVIDER_URL, "corbaloc:rir:/NameServiceServerRoot");
        Context context = new InitialContext(env);

        SomeEJBServiceClassHome remoteObject = (SomeEJBServiceClassHome) getRemoteObject(context, SomeEJBServiceClassHome.class.getName());
        SomeEJBServiceClassBusiness = remoteObject.create();
    } catch (NamingException e) {
        LOG.error("Error getting EJB " + SomeEJBServiceClassHome.class.getName());
    } catch (CreateException e) {
        LOG.error("Error creating EJB " + SomeEJBServiceClassHome.class.getName());
    }
    return SomeEJBServiceClassBusiness;
}

public Object getRemoteObject(Context ctx, String jndiName) throws NamingException {
    Object obj;
    StringBuffer fullJndiName;
    try {
        fullJndiName = new StringBuffer();
        fullJndiName.append("java:comp/env/").append(jndiName);
        LOG.debug("Trying connect to [" + fullJndiName.toString() + "]");
        obj = ctx.lookup(fullJndiName.toString());
    } catch (NamingException e) {
        try {
            fullJndiName = new StringBuffer();
            fullJndiName.append("java:comp/").append(jndiName);
            LOG.debug("Trying connect to [" + fullJndiName.toString() + "]");
            obj = ctx.lookup(fullJndiName.toString());
        } catch (NamingException e0) {
            try {
                fullJndiName = new StringBuffer();
                fullJndiName.append(jndiName);
                LOG.debug("Trying connect to [" + fullJndiName.toString() + "]");
                obj = ctx.lookup(fullJndiName.toString());
            } catch (NamingException e1) {
                throw e;
            }
        }
    }
    return obj;
}

但是现在当我需要将 WAR 移到 EAR 之外时,这不再起作用了。因为我需要使用 EJBHome 和 EJBBusiness 复制一个 JAR(从 EAR 内部)作为我的 WAR 库。WAR应用程序有没有办法在EAR(不同的应用程序)中使用EJB而不复制任何jar?

4

0 回答 0