Contributed By: Łukasz Budnik
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!
Standard Maven archetypes are pretty out of date, and you need to update the version used by the project.
Run the project directly from NetBeans (shortcut key: [F6]).
There will be an error:
[ERROR]No suitable Deployment Server is defined for the project or globally. [ERROR]Mojo: [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]Reason: [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 .war file. You also need to specify the relative so that it includes the service. To specify the server and relative URL, perform these steps:
The application is deployed, but http://localhost:8080/JAXWSWebApp/MathService displays a generic Hello, World! message, and http://localhost:8080/JAXWSWebApp/MathService?wsdl gives a 404 error.
As I wrote before, Maven archetypes are pretty out of date. Open /WEB-INF/web.xml and replace the old web 2.3 descriptor:
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" > <web-app> <display-name>Archetype Created Web Application</display-name> </web-app>
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> </web-app>
Redeploy and run the application. You see an information page about the service at http://localhost:8080/JAXWSWebApp/MathService.
The link to the WSDL on this page does not work, but you can view the WSDL by appending ?wsdl 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 Tester as a query string, just like this:
http://localhost:8080/JAXWSWebApp/MathService?Tester
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.
| glashfish_web_service_tester.PNG | ![]() |
12287 bytes |
| glashfish_web_service_tester.png | ![]() |
12287 bytes |
| nb_maven2.png | ![]() |
35780 bytes |
| nb_maven2_archetype.PNG | ![]() |
35528 bytes |
| nb_maven2_archetype.png | ![]() |
35528 bytes |
| nb_server.PNG | ![]() |
22338 bytes |
| nb_server.png | ![]() |
48034 bytes |
| ws-info.png | ![]() |
13545 bytes |