JAX-WS Web Services in a Java EE 5 Web Application (using Netbeans 6, Maven2, and GlassFish V2)

Contributed By: Łukasz Budnik

[[{TableOfContentsTitle=TableOfContents} | {TableOfContents title='Table of Contents'}]]


If we deploy our applications on a Java EE 5 compliant server, we don't need to use any external engines in order to expose parts of our functionality as Web Services – Java EE 5 compliant servers have it all.

Throughout this tutorial, we will be developing a simple Jave EE 5 Web Application which will expose some of its functionality as a JAX-WS Web Service.

We will be using NetBeans 6, Maven2, and GlassFish V2.

This tutorial assumes you have a basic knowledge of JAX-WS technology and Maven2. Also it is assumed that you have Maven plugin already installed.

Let's get started!

Beginning Project

  1. Open NetBeans 6 and create a new project. In
    New Project
    window select {Maven Project}:http://wiki.netbeans.org/attach/JAXWSNB6Maven2GlassFishV2/nb_maven2_JAXWSNB6Maven2GlassFishV2.png
  2. Click
    . The Maven Archetype window opens.
  3. In the Maven Archetype window select
    Maven Webapp Archetype
  4. Click Next. The Name and Location window opens.
  5. In the Name and Location window, name the project JAXWSWebService and accept the default options for the other values.

Amending project settings

Standard Maven archetypes are pretty out of date, and you need to update the version used by the project.

  1. After the project is created, right click it and select
  2. In the
    tab, select source level of at least {1.5}, and make sure that the encoding is set to UTF-8.

Writing simple JAX-WS Web Service

  1. Create a new package, call it
  2. Create the
    class in the new package.
  3. Copy and paste the following code into

@WebService public class Math {

 public int add(int a, int b) {
     return a + b;

} </pre>

  1. Add import statements for
    and <tt>{javax.jws.WebMethod
  2. Save this file.

Deploying the project

Run the project directly from NetBeans (shortcut key:

There will be an error:

[ERROR]No suitable Deployment Server is defined for the project or globally.
[ERROR]    org.codehaus.mevenide:netbeans-deploy-plugin:1.2.4:deploy
[ERROR]FAILED for project:
[ERROR]    org.xh.studies.jaxws.webapp:JAXWSWebApp:war:1.0-SNAPSHOT
[ERROR]No suitable Deployment Server is defined for the project or globally.
To fix this error, you need to specify the application server on which you deploy the
file. You also need to specify the relative so that it includes the service. To specify the server and relative URL, perform these steps:
  1. Right-click the project and select
    . Navigate to the {Run} tab.
  2. In the Server field select GlassFish V2, and in the Relative URL field, type /MathService.http://wiki.netbeans.org/attach/JAXWSNB6Maven2GlassFishV2/nb_server_JAXWSNB6Maven2GlassFishV2.png
  3. Save the changes and run the application once again.
The application is deployed, but
displays a generic Hello, World! message, and {http://localhost:8080/JAXWSWebApp/MathService?wsdl} gives a 404 error.

Amending the web.xml descriptor

As I wrote before, Maven archetypes are pretty out of date. Open
and replace the old web 2.3 descriptor:
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >

<display-name>Archetype Created Web Application</display-name>

with a 2.5 compliant one:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name>Archetype Created Web Application</display-name>

Running the project

Redeploy and run the application. You see an information page about the service at


The link to the WSDL on this page does not work, but you can view the WSDL by appending
to the URL of the information page ({http://localhost:8080/JAXWSWebApp/MathService?wsdl}). If you use GlassFish V2, you can test all deployed Web Services by appending
as a query string, just like this:

The above URL generates a simple web form which can be used for quick testing:



Congratulations you have just written your very first JAX-WS Web Service using NetBeans 6, Maven2, and GlassFish V2.

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo