#
EJB Client (Stateless)
This tutorial explains ou how to code a Java EJB Client for a stateless EJB3 deployed on Weblogic 12c.
This article is using:
- Eclipse Java EE IDE for Web Developers, Version: Neon.3 Release (4.6.3)
- Java 8
The Enterprise Java Bean is deployed on the Oracle WebLogic 12c.
You have to add to your new Java Project the MyEJB project to the build path:
You have to add to your new Java Project the weblogic.jar and wlclient.jar (are in the WebLogic download package):
Now it time for coding. Here is the class I added to the project:
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import ejb.AddIntegersRemoteInterface;
public class RunClient {
public static void main (String[] args) throws NamingException {
System.out.println("Start EJB3 Client for connecting to Weblogic");
final Hashtable jndiProperties = new Hashtable();
jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
jndiProperties.put(Context.PROVIDER_URL,"t3://localhost:7001");
Context ctx = new InitialContext(jndiProperties);
System.out.println("Initial Context created");
AddIntegersRemoteInterface addIntegers =
(AddIntegersRemoteInterface) ctx.lookup("AddIntegers#ejb.AddIntegersRemoteInterface");
System.out.println("lookup successful");
//Remote EJB function call
System.out.println(addIntegers.returnSuma(1, 3));
System.out.println("EJB3 Client : END");
}
}
I run the project as "Java Application" and here is the result: