Sunday, March 23, 2008

EJB 3 In Action Examples on WebLogic 10

Several readers requested me to provide the code examples of EJB 3 in Action for BEA WebLogic 10. We have earlier provided examples for Glassfish, Oracle Application Server and JBoss. I spent sometime last weekend to port these examples to Weblogic 10. You can download examples for first four chapters.

These examples have been modified to run on the default examplesServer on the Weblogic in the default server domain. To run the examples, first the set the environment variables by the running the SetExamplesEnv script in $BEA_HOME/wlserver_10.0/samples/domains/wl_server directory.

For example, if you are running on Windows and you have installed WebLogic 10 in C:\bea\wlserver_10.0\ directory you can run the script as follows:


If you unzipped the samples in c:\WLS examples change directory to chapter 1 and you can build and deploy as follows:

cd c:\WLS examples\chapter1

ant - -> attempts to build and deploy in the examplesServer

To run the example:

ant run

You must be wondering what are the changes that I made in the to run on WebLogic 10.

Java EE promises write once run anywhere ! Then why I had to make changes in the code?

Every application server has its minor quirks here and there and code changes were very minimal.

I could not make dependency injection work in the application client code in WebLogic 10, not sure they support it. So I had to change thick client to make use JNDI lookup instead. I modified the Session bean code to define a global JNDI name for the HelloUser session bean as follows: @Stateless(mappedName="HelloUser")

public class HelloUserBean implements HelloUser

I modified the client code to lookup the remote EJB as follows:

Context ctx = new InitialContext(); helloUser = (HelloUser) ctx.lookup("HelloUser#ejb3inaction.example.HelloUser");

As you would expect, I updated the in the client jar file to have right environment properties for WebLogic as follows:


That's it ..

In the next blog entry, I will discuss the code changes the instructions to run Chapter 2-4 and outline changes made to run JPA and MDB examples.


Meera Subbarao said...

Hi Debu,
When I tried deploying a simple EJB3 application to WebLogic 9 and 10, it complained about the ejb-jar.xml descriptor. I was assuming that this was optional in EJB3. Is it still mandatory in WebLogic?

Meera Subbarao

Debu Panda said...

I think that was an issue with WebLogic 10 preview. Nope, you do not need an ejb-jar.xml if you are using annotations in the production version of WebLogic 10.

Abishek Kumar said...

Hi Debu,
Iam new to EJB and have to do my academic project on EJB3. Iam using netbeans with glassfish, if you can please tell me if you have written any blog about EJB in netbeanside with glassfish server..! it would be gr8 help.
Please let me know..!

Anonymous said...


I was only curious to see if the files for chapter1 would run as describded by you. I works like charm.

Thanks for the good job.

Have a good day


Anonymous said...

Thanks for the samples. and they are working fine.
I just had a query rather i would like to get your suggession on following
- I am in the process of finalizing the architecture for my new porject. This project would have Swing based Client, MQ based messaging interface and lot of data access from DB.i have decided to make use of EJB3 and Weblogic 10 for serverside API. what i can not decide is which JPA provider i should use? Hibernate, KODO or something else.
Your input would be valuable.

Dan said...


I built your Chapter1 example and it ran fine. However, when I moved
the client to a different machine (copied the entire .zip and re-built
with the IP/port pointing to my first machine), I got a ClassNotFoundException on the ctx.lookup... Can you tell me what's missing? thanks..

Damodar Mukhopadhyay said...

Hi Debu,

I was trying to port some code in the weblogic server 10 and Your blog helped me a lot. I also like to thank you for the EJB3 in Action, Its really a great book.

Wish You all the best for future.


Anonymous said...


The examples works fine. But when I converted to ejb to webservice :
package ejb3inaction.example;

import javax.ejb.Stateless;
import javax.jws.WebMethod;
import javax.jws.WebService;


public class HelloUserBean implements HelloUser {

public HelloUserBean() {


public void sayHello(String name) {
System.out.println("Hello " + name + " welcome to EJB 3 In Action!");

It doesn't deploy. It throws :
java.lang.ClassNotFoundException: ejb3inaction.example.HelloUserBean_oww2xs_WSOImpl

Could you please help me out in deploying as webservice