[英]How to Use single EJB for both client application and Web application
I am very new to this EJB concept. 我对这个EJB概念非常陌生。 I am assigned a task to develop an application which is a replica of netflix.
我分配了一个任务来开发一个应用程序,该应用程序是netflix的副本。 We have two modules:
我们有两个模块:
How do I line both desktop application and web based application for single EJB? 如何为单个EJB排列桌面应用程序和基于Web的应用程序?
So you have an EJB deployed in an app server (eg Glassfish, JBoss, etc) and you want clients from a desktop (J2SE) and web (eg Tomcat) app to use this (remote, of course) EJB. 因此,您在应用服务器(例如Glassfish,JBoss等)中部署了EJB,并且希望桌面(J2SE)和Web(例如Tomcat)应用中的客户端使用该EJB(当然是远程的)。
If that's what you have, you need your clients to connect to the remote EJB using JNDI, as follows (JBoss example): 如果是这样,则需要您的客户端使用JNDI连接到远程EJB,如下所示(JBoss示例):
try {
Context context = new InitialContext(getJNDISetup());
MyServiceEJBRemote delegate = (MyServiceEJBRemote)context.lookup(MY_SERVICEEJB_JNDI_NAME);
} catch (NamingException e) {
// log exception
}
private static Hashtable<?, ?> getJNDISetup() {
// perform jndi lookup with your favorite method, hashtable, properties file... in this case, hashtable.
Hashtable<String, String> setup = new Hashtable<String, String>();
setup.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
setup.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
setup.put("java.naming.provider.url","localhost:1099");
return setup;
}
Depending on your app server you might need to modify the key elements defined in the HashMap. 根据您的应用服务器,您可能需要修改HashMap中定义的关键元素。
Your clients (destkop, web) will need to be aware of the EJB interface obviously. 您的客户(destkop,web)显然需要了解EJB接口。 Both the web server and the desktop module will need also the app server naming libraries.
Web服务器和桌面模块都将需要应用服务器命名库。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.