简体   繁体   中英

How to Use single EJB for both client application and Web application

I am very new to this EJB concept. I am assigned a task to develop an application which is a replica of netflix. We have two modules:

  • Owner will have a desktop application
  • users will have web application.

How do I line both desktop application and web based application for single EJB?

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.

If that's what you have, you need your clients to connect to the remote EJB using JNDI, as follows (JBoss example):

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.

Your clients (destkop, web) will need to be aware of the EJB interface obviously. Both the web server and the desktop module will need also the app server naming libraries.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM