This is a new series of blogs which will cover what is new in JavaEE 6 with respect to WebServices

One of the new features of JavaEE 6 is ability to package ejb in a war. The EJB specification has always required that enterprise beans
be packaged in an enterprise module called an ejb-jarfile.
Since it is common for Java EE web applications to use enterprise beans, this packaging requirement can be burdensome.
EJB 3.1 addresses this packaging complexity by removing the restriction that enterprise bean classes must be packaged in anejb-jar file.
You can now place EJB classes directly in the .warfile, using the same packaging guidelines that apply to web application classes.
This means that you can place EJB classes under theWEB-INF/classes directory or in a .jarfile within the WEB-INF/lib directory.
The EJB deployment descriptor is also optional. If you need it, you can package the EJB deployment descriptor as aWEB-INF/ejb-jar.xml file. 

So we extend the above idea to demonstrate ejb webservices in a war file.

The following blog shows how simple it is to create and deploy ejb webservices in war using Netbeans 6.9 ( and Glassfish 3.0.1 (

Lets begin by creating a Web Application using Netbeans 6.9

choose project

 Next we specify the project location

name and location


 Select Glassfish 3.0.1 which is bundled with Netbeans 6.9 as the server. Note I use JavaEE 6 as the version .

server and settings


Now we create a WebService say a Weather service which will show the temperature for a zip code. We implement the WebService as a Stateless Session Bean

name and loc


Click Finish

Here is the code to the WebService . Note I have added a WebMethod. I have also specified an Interceptors annotation. EJB 3.0 interceptors provide developer

with fine grained control over method invocation flow. In this example we print the method from which the Interceptor was called.




Here is the code of This prints the name of the the method obtained from the InvocationContext.


 Next we Clean and Build the project

Then click on Deploy.

You can browse the wsdl from here


Note (Ejb WebServices in war is merely a packaging convenience. The URL at which the endpoint is deployed is the same as if an ejb was deployed in a ejb-jar file. There was a bug in

Glassfish v3 where ejb webservices in war were being treated as webapps. This has been addressed in GF 3.0.1 and the GF 3.1)



So you see with Netbeans it is very easy to build, deploy ejb webservices in war. You can also test the webservice by

using the tester app at http://localhost:8080/WeatherService/Weather?tester and enter a zip code (Ofcourse you will get the hardcoded 70 degress)

Additional Information

Java EE 6 technologies

EJB 3.1 specification

JSR 109 specification