Wednesday, 1 May 2013

Deploy Web Service On Tomcat Server

Deploy Web Service On Tomcat Server

There are following steps to create web service and deploy it on tomcat server
Step 1 :Create a web service
package com.test.ws;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
@WebService
@SOAPBinding(style = Style.RPC)
public interface HelloWorld{
@WebMethod String sayHello();
}

package com.test.ws;
import javax.jws.WebService;
@WebService(endpointInterface = "com.test.ws.HelloWorld")
public class HelloWorldImpl implements HelloWorld{
@Override
public String sayHello() {
return "Hello World";
}
}

Later you will deploy this web service on tomcat server

Step 2 : sun-jaxws.xml
Create a web service deployment descriptor, sun-jaxws.xml.


When user access /hello/ URL path, it will access the declared web service, which is HelloWorldImpl.java.

Step 3 : web.xml
Create a web.xml deployment descriptor for the deployment. Defines WSServletContextListener as listener class,
and WSServlet as your servlet.

Step 4 : War content for deployment

WEB-INF/classes/com/test/ws/HelloWorld.class
WEB-INF/classes/com/test/ws/HelloWorldImpl.class
WEB-INF/web.xml
WEB-INF/sun-jaxws.xml
Step 5 : Download a web service dependency from here :http://jax-ws.java.net/
put all jar files in the lib folder as :
jaxb-impl.jar
jaxws-api.jar
jaxws-rt.jar
gmbal-api-only.jar
management-api.jar
stax-ex.jar
streambuffer.jar
policy.jar
Step 6 : Deployment on tomcat
create war file with lib folder as given above and deploy on tomcat webapps folder
Restart the tomcat server , now you can access the url as

http://localhost:8080/HelloWorld/hello , if you see the following page output then you are successfully
deployed the web service on tomcat.
Done !

No comments:

Post a Comment