Connecting Remote EJB3 from a Servlet with WebLogic 10.3

Right now i’m trying to connect 2 different applications that located in a different server. Im using remote EJB3 to connecting them, with Apache Tomcat as server 1 and WebLogic 10.3 as server 2. Im using Netbeans 6.8 as primary IDE for this test.

create an EJB Module Project from Netbeans IDE, and create these files

first is the remote interface

package com.edw.ejb3;

import javax.ejb.Remote;

public interface HelloEJBRemote {
    String sayHello(final String name);    

and the ejb implementation

package com.edw.ejb3;

import javax.ejb.Stateless;

public class HelloEJB implements HelloEJBRemote {
    public String sayHello(final String name) {
        return "Hello "+name+" how do you do?";

Package it as JAR or EAR, start Weblogic then use Admin Console (default: http://localhost:7001/ ) to deploy the EJB.

and to make sure, you can check EJB’s JNDI
ejb's jndi

next is creating a Web Project, dont forget to include your EJB project to your Web Project’s library.

create a servlet file to perform a connection to Remote EJBs.

package ejb;

import com.edw.ejb3.HelloEJBRemote;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class EJBServlet extends HttpServlet {

   protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        PrintWriter out = response.getWriter();
        try {

            Hashtable<String, String> env = new Hashtable<String, String>();
            env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
            env.put(Context.PROVIDER_URL, "t3://localhost:7001");

            Context ic = new InitialContext(env);

            HelloEJBRemote remote = (HelloEJBRemote) ic.lookup("HelloEJB#com.edw.ejb3.HelloEJBRemote");


        } catch (Exception ex) {
        } finally {

and this is my web.xml configuration file

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="" xmlns:xsi="" xsi:schemaLocation="">

if you find this error,

javax.naming.NoInitialContextException: Cannot instantiate class: weblogic.jndi.WLInitialContextFactory [Root exception is java.lang.ClassNotFoundException: weblogic.jndi.WLInitialContextFactory]

it happen because you havent put wlfullclient.jar (WebLogic library) into your Apache Tomcat’s library folder. You can find it in your Weblogic installation folder ({weblogic}\server\lib) or you can create it your self, by executing wljarbuilder.jar.

java -jar wljarbuilder.jar

tomcat libs

you can test your app by running your web project from your IDE.
web content

this is my netbeans project structure
Netbeans Project Structure




about 7 years ago

holla win... gua nyampah dikit di blog elo deh...wkwkwk



about 7 years ago

hahaa, jangan cuman nyampah. Kasih ide kek...


about 6 years ago

hi.. great blog. I m trying to do the same using OEPE. But I cant see the JNDI updated after I publish my EJB project on the server. EJB is deployed and shows under the Deployments table. Second thing, Is it ok, if I make web app and deploy it on same server and then access it without Apache ?? thanks



about 6 years ago

hi suhas, thanks for your questions, 1. have you tried to exposed your EJB remote interfaces? If your EJBs are exposed, they should have a JNDI pattern like this --> MapedName#package.RemoteBeanName. 2. It's okay to deploy a webapp on a same VM or server with your EJB app. And you can exposed your EJB as a Local or Remote EJB. You can find a good article about when to use Local or Remote EJB here.


about 4 years ago

Are you still around? If so I have tried and tried this. I have tried many of the online examples. And I keep getting the same error: Uncaught [[o:Exception]:"java.lang.Exception: Invoke failed: [[o:InitialContext]]->lookup((o:String)[o:String]). Cause: javax.naming.NameNotFoundException: Name [] is not bound in this Context. Unable to find []. VM: 1.7.0_09@" at Can you help?



about 4 years ago

Yes Tommy, as you can seem the error happen because of "Name []" perhaps your application cannot connect to your Context.PROVIDER_URL url try to ping or telnet to the destination Weblogic. :)


about 4 years ago

Thanks Edwin ....Very useful tutorial ....



about 4 years ago

Hi Eswar, glad it could help :)

Leave a Comment

Please be polite. We appreciate that.
Your email address will not be published and required fields are marked

:-[ (B) (^) (P) (@) (O) (D) :-S ;-( (C) (&) :-$ (E) (~) (K) (I) (L) (8) :-O (T) (G) (F) :-( (H) :-) (*) :-D (N) (Y) :-P (U) (W) ;-)