JAX-WS webservice deployment on tomcat

In previous post,we have seen how to develop JAX-WS web service end point and client.In this post,we will see how we can deploy web service end point to application server.

Web service Tutorial Content:

    Introduction to web services Web services interview questions SOAP web service introduction RESTful web service introduction Difference between SOAP and REST web services SOAP web service example in java using eclipse JAX-WS web service eclipse tutorial JAX-WS web service deployment on tomcat Create RESTful web service in java(JAX-RS) using jersey RESTful web service JAXRS json example using jersey RESTful web service JAXRS CRUD example using jersey AngularJS RESTful web service JAXRS CRUD example using $http RESTful Web Services (JAX-RS) @QueryParam Example Spring Rest simple example Spring Rest json example Spring Rest xml example Spring Rest CRUD example
Here we will use tomcat as application server.

1) Open eclipse.
2) Create new dynamic web project named "HelloWorldWS"
3) Create new package named "org.arpit.javapostsforlearning.webservice"

 4) Create JAXWSService Interface.
package org.arpit.javapostsforlearning.webservice;
import javax.jws.WebMethod;
import javax.jws.WebService;

public interface HelloWorld {

 @WebMethod public String helloWorld(String name);
5)Create JAXWSService implementation class.
package org.arpit.javapostsforlearning.webservice;
import javax.jws.WebService;

public class HelloWorldImpl implements HelloWorld{

 public String helloWorld(String name) {
  return "Hello world from "+name;


6) Now , you need generate Web Services classes, open your command line, and type :
/* Now You need do following, 
1) open command prompt.Go to your eclipse workspace(For example: cd E:/arpit/workspace) 
2) then go to project(For example if project name is jaxws then "cd jaxws") 
3) paste following "wsgen -s src -d build/classes -cp build/classes org.arpit.javapostsforlearning.webservice.HelloWorldImpl" then enter */
cd %project_home%
wsgen -s src -d build/classes -cp build/classes org.arpit.javapostsforlearning.webservice.HelloworldImpl

Now we will have two class generated under src/org/arpit/javapostsforlearning/webservice/jaxws

7)Now you need to create web.xml and put it under /HelloWorldWS/WebContent/WEB-INF/
<?xml version="1.0" encoding="UTF-8"?>
we have inserted three things here 1.listner-class 2.servlet 3.servlet-mapping
8) Now we will add sun-jaxws.xml under HelloWorldWS/WebContent/WEB-INF/.It will have endpoint definition.

<?xml version="1.0" encoding="UTF-8"?>
<endpoints xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime" version="2.0">
9) We need to download some jaxws jars and put jars under /HelloWorldWS/WebContent/WEB-INF/lib.
click to begin
5.93MB .zip

10) Now export your project as war and put it under your Tomcat webapps folder.
11) If you have target runtime as none then you can refer configure Apache Tomcat in Eclipse IDE.
then Run tomcat
12) Click this URL http://localhost:8080/HelloWorldWS/HelloWorldWS
If You see web service information page then you are done.

Written by Arpit:

If you have read the post and liked it. Please connect with me on Facebook | Twitter | Google Plus


Java tutorial for beginners Copyright © 2012