Thursday, June 26, 2008

EJB 3 Stateless bean Web service in WebLogic Server

I recently got some questions from customers about the procedure for deploying EJB 3 Session Bean Web service in WebLogic 10. In this blog, I will outline the steps.

First develop your EJB3 session bean web service as follows:

serviceName="PlaceBidService", portName = "PlaceBidPort",
targetNamespace = "")
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT)
public class PlaceBidBean {


public Long addBid(String userId, Long itemId, Double bidPrice) throws BidException {





Unlike OC4J, WebLogic do not support parsing of JAX-WS annotations at deployment time and if you try to deploy the compiled EJB 3 Web service, you will get deployment time exception. You have to run the EJB 3 WS thru annotation parsing tool (jwsc –java web services compile) supplied with WebLogic to generate the artifacts and package in your ejb-jar module.

Here is an example ant task to create the web service:

name="build-ws-server" description="Target that builds the
target Web Service">
file="actionbazaar/buslogic/" type="JAXWS"

<target name="package-ejb"

<mkdir dir="${bld.ejb.dir}/actionbazaar/buslogic/jaxws" />

<copy todir="${bld.ejb.dir}/actionbazaar/buslogic/jaxws">

<fileset dir="${bld.service.dir}/actionbazaar/buslogic/PlaceBidBean/actionbazaar/buslogic/jaxws" includes="*"/> </copy>
<echo message="-----> Create EJB jar file"/>
<jar jarfile="${bld.ear.dir}/${}.jar">
<fileset dir="${bld.ejb.dir}" includes="**" />
</target >

Make sure to package the generated artifacts in the EJB JAR and then deploy the EJB-JAR or EAR to the WebLogic Server. Note that if your web service depends upon custom Java objects - the generated artifacts contain duplicate Java classes that you already may have. These duplicated classes are on a separate package structure and cause ClassCastException for me. So I avoid packaging these classes.

Accessing EJB 3 Web service

After successful deployment you can access the web service as follows:



Hope this helps.

You can download the working examples from here. Chapter 15 contains web services example.


Anonymous said...

Hy this example works fine for me, but i need to specify a context for my web service. Just like the @WebContext( does.

Do u know how i can do that?


Anonymous said...

Hi there

How do you get jwsc to package a persistence.xml file into the generated ear file when you want to use a webservice which is build on a stateless session bean, which in turn is a facade on a collection of entity beans

Anonymous said...

Hi Debu,

Thank you for the article and the update for WLS. I just want to point out that at least in WLS 10gR3 you do not need to run an ant script to accomplish deployment.

I was able to deploy this bean dumbed down to echo hello from Oracle WebLogic Workshop with annotations and then expose the bean on OSB (Oracle Service Bus ) as a business service and it worked like a champ.

For additional reference, I used James Bayers's blog at

for the workshop pieces. I will put together a post together on this in the near future.

Once again thank you, the book has been very helpful.

Matt Baldwin

Cali said...

Hi, Matt.
How do you expose it on OSB? Is EJB3 supported in OSB 10gR3?
Carlos Gremmelmaier

prathap kumar said...

Interesting Article

EJB 3 Online Training | Online Java Training

Java J2EE Online Training | Core Java Online Training