Tutorial : Java stand alone application calls EJBs
After the tutorial about MyJava, I have created this topic for remembering my EJB. Actually, we have to create Servlet and deploy to the J2EE container, so the Servlet can find the EJB. However, if you want to use stand alone application to call the EJB. The PROVIDER_URL should be defined, hence the application can connect to the EJB. If we didn’t define the PROVIDER_URL in application, the application won’t find the EJB name on JNDI.
define the PROVIDER_URL and INITIAL_CONTEXT_FACTORY, this setting is for Jboss, you might have to look at your application server document.
env.put(Context.PROVIDER_URL, "jnp://127.0.0.1:1099");
Context ct = new InitialContext(env);
Object o = ct.lookup("${Your EJB}");
YourHomeInterface eh = (YourHomeInterface) PortableRemoteObject.narrow(o, YouHomeInterface.class);
YourRemoteInterface h = eh.create();
System.out.println(YourRemoteInterface.YourMethod("Hello")); Invoke the method
This is my file and example



