Accessing EJB Component from non j2ee application

I am trying to access a stateless session bean on a remote Websphere server from a java application. This is not a servlet and does not run in a web container, it's a plain old java app. Here is the code that is giving me trouble:

Context initial = new InitialContext();            
Object o = initial.lookup("corbaname:iiop:wasdev3a:2810#ejb/com/xxxx/xxx/services/membersearch/ejb/MemberSearchServiceEjbBean");

I get this exception:

javax.naming.NameNotFoundException [Root exception is org.omg.CosNaming.NamingContextPackage.NotFound:]
      at com.sun.jndi.cosnaming.ExceptionMapper.mapException(
      at com.sun.jndi.cosnaming.CNCtx.callResolve(
      at com.sun.jndi.cosnaming.CNCtx.lookup(
      at com.sun.jndi.toolkit.url.GenericURLContext.lookup(
      at javax.naming.InitialContext.lookup(
      at com.ibx.ecomm.mistool.Main2.main(
Caused by: org.omg.CosNaming.NamingContextPackage.NotFound:
      at org.omg.CosNaming._NamingContextStub.resolve(
      at com.sun.jndi.cosnaming.CNCtx.callResolve(
      ... 4 more
Exception in thread "main"

Can anyone give me any pointers on invoking an ejb from a plain old java app. First solution that actually works wins the points.
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

damonfConnect With a Mentor Commented:
Do you have the EJB client jar from that session bean?  Got to have that in your java app first.

Next, you need code like this to do the JNDI lookup:

             parms.put(Context.PROVIDER_URL, "iiop://hostserver:9999/"); //where 9999 is the iiop port
             Context ctx = new InitialContext(parms);
then do your lookup
aamir75Connect With a Mentor Commented:
For your scenario you first have to install Pluggable Application Client. After that you have to run setupclient.bat file from command line. It will prepare environemnt (it will initialize the necessary environment variables pointing to the necessary jar files and directories). After that you can run your application by executing following command line:

%JAVA_HOME%/bin/java -Xbootclasspath/p:%WAS_BOOTCLASSPATH%
-classpath <classpath JARs>
-Djava.ext.dirs=%WAS_EXT_DIRS% -Djava.naming.provider.url=iiop://localhost
%SERVER_ROOT% %CLIENTSAS% <class containing main method>

you can see the variables like this %WAS_BOOTCLASSPATH%, these are the variables set by setupclient.bat.

You should get the initial context like this:

  Context ic = new InitialContext();
  String lookupString
            = "cell/nodes/localhost/servers/server1/ejb/dash/hr/services/EmployeeServiceHome";

For more info:

Good Luck!
Muhammad Aamir
All Courses

From novice to tech pro — start learning today.