Over a million developers have joined DZone.

JAX-WS Deployment Five Minute Tutorial

DZone's Guide to

JAX-WS Deployment Five Minute Tutorial

· Java Zone
Free Resource

Managing a MongoDB deployment? Take a load off and live migrate to MongoDB Atlas, the official automated service, with little to no downtime.

After we explained how we can implement a JAX-WS web service (endpoint, client) in the JAX-WS Five Minute Tutorial, we will continue by explaining how we can deploy the web service endpoint on any application server... and here we'll use Tomcat.

To deploy your WS endpoint you need to package it as a war first then deploy it on your application server.

Note:- You can download the source code for this example from the resources section.

Ok, lets begin

 1) Open Eclipse.

2) Create a new Web project .

3) Create your Web Service interface (Greeting):

package juma.mohammad;import javax.jws.WebMethod;import javax.jws.WebService;@WebServicepublic interface Greeting { @WebMethod String sayHello(String name);}

 4) Create your Web Service implementation (GreetingImpl):

package juma.mohammad;import javax.jws.WebService;@WebService(endpointInterface = "juma.mohammad.Greeting")public class GreetingImpl implements Greeting {@Overridepublic String sayHello(String name) {return "Hello, Welcom to jax-ws " + name;}}

 5) Now , you need generate Web Services classes, open your command line, and type :

cd %project_home%wsgen -s src -d build/classes -cp build/classes juma.mohammad.GreetingImpl

Good , now you have two classe(SayHello.java, SayHelloResponse.java) generated under /greetingWS/src/juma/mohammad/jaxws  .

6) Now we need to write our web.xml and put it under /greetingWS/WebContent/WEB-INF

<?xml version="1.0" encoding="UTF-8"?><web-app     xmlns="http://java.sun.com/xml/ns/j2ee"     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee                         http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"     version="2.4">   <listener>     <listener-class>        com.sun.xml.ws.transport.http.servlet.WSServletContextListener     </listener-class>   </listener>   <servlet>      <servlet-name>GreetingWS</servlet-name>      <servlet-class>        com.sun.xml.ws.transport.http.servlet.WSServlet      </servlet-class>   </servlet>   <servlet-mapping>     <servlet-name>GreetingWS</servlet-name>     <url-pattern>/greeting</url-pattern>   </servlet-mapping></web-app>

Note that in this web.xml we  just defined two things : 1) listener-class, 2)servlet !

7) ok,the final step is that you need to add sun-jaxws.xml under /greetingWS/WebContent/WEB-INF  which contains endpoints definition:

<?xml version="1.0" encoding="UTF-8"?><endpoints xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime" version="2.0">  <endpoint     name="GreetingWS"     implementation="juma.mohammad.GreetingImpl"     url-pattern="/greeting"/></endpoints> 

8) You need to download JAX-WS library and put jars under /greetingWS/WebContent/WEB-INF/lib.

You can get jars from the attached sample :)

9) Great, now you just need to export this project as a war, and drop it under your Tomcat webapps folder .

10) Run Tomcat.

11) Try this url: http://localhost:8080/greetingWS/greeting

Congratulations... web service information page appeared :)

MongoDB Atlas is the easiest way to run the fastest-growing database for modern applications — no installation, setup, or configuration required. Easily live migrate an existing workload or start with 512MB of storage for free.

java ,jax-ws

Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}