Search code examples
javaswingremote-accesswebsphere-libertyejb-3.2

Assuming a CLI or Swing interface client, how is a remote Bean accessed through Liberty


I want to access to remote EJB running on Liberty Server from a swing Client like this :

Object found = new InitialContext().lookup(
"corbaloc:iiop:localhost:2809#ejb/ear/ejb.jar/package/Bean#com.package.BeanRemote);

I'm getting that error :

javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or in an application resource file: java.naming.factory.initial
                    at java.naming/javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:691)
                    at java.naming/javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:305)
                    at java.naming/javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:342)
                    at java.naming/javax.naming.InitialContext.lookup(InitialContext.java:409)
                    at com.package.ClassMain.main(ClassMain.java:43)

How is a connection to Liberty established? Need help please


Solution

  • I'd strongly recommend you to re-architect your app to use JAX-RS (rest over http) instead of remote EJB. Just use Facade pattern and wrap your EJB as REST endpoints, and use Rest client on the Swing side.

    There are several reasons:

    • remote EJB is almost dead technology now
    • http/rest is more firewall/network/container friendly
    • http/rest is more client agnostic - if you would later like to change your client from Swing to web/JS it will be much easier

    But if you really insist, setting up remote EJB is not very simple.

    The easiest would be to use Liberty Application client and run your Swing app from there.

    If you cannot use that you will need to get traditional WebSphere Application Server Client, and use the client jar provided with that com.ibm.ws.ejb.thinclient_8.5.0.jar. If the client is running with a non-IBM java you will also need to add the orb jar onto the class path (com.ibm.ws.orb_8.5.0.jar).

    See theses links:

    So all in all, rewrite will be usually simpler and more beneficial.