我的项目结构如下:
- > WebSphere Application Server(WAS)
- - - - > EAR
--------> EJB模块
--------> EJB客户端
- - - - > WAR
--------> 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?