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):
01.package juma.mohammad;02. 03.import javax.jws.WebMethod;04.import javax.jws.WebService;05. 06.@WebService07.public interface Greeting {08.@WebMethod String sayHello(String name);09.}01.package juma.mohammad;02. 03.import javax.jws.WebService;04. 05.@WebService(endpointInterface = "juma.mohammad.Greeting")06.public class GreetingImpl implements Greeting {07. 08.@Override09.public String sayHello(String name) {10.return "Hello, Welcom to jax-ws " + name;11.}12. 13.}1.cd %project_home%2.wsgen -s src -d build/classes -cp build/classes juma.mohammad.GreetingImpl6) Now we need to write our web.xml and put it under /greetingWS/WebContent/WEB-INF
01.<?xml version="1.0" encoding="UTF-8"?>02.<web-app03.xmlns="http://java.sun.com/xml/ns/j2ee"04.xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"05.xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee07.version="2.4">08.<listener>09.<listener-class>10.com.sun.xml.ws.transport.http.servlet.WSServletContextListener11.</listener-class>12.</listener>13.<servlet>14.<servlet-name>GreetingWS</servlet-name>15.<servlet-class>16.com.sun.xml.ws.transport.http.servlet.WSServlet17.</servlet-class>18. 19.</servlet>20.<servlet-mapping>21.<servlet-name>GreetingWS</servlet-name>22.<url-pattern>/greeting</url-pattern>23.</servlet-mapping>24.</web-app>7) ok,the final step is that you need to add sun-jaxws.xml under /greetingWS/WebContent/WEB-INF which contains endpoints definition:
1.<?xml version="1.0" encoding="UTF-8"?>2.<endpoints xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime" version="2.0">3.<endpoint4.name="GreetingWS"5.implementation="juma.mohammad.GreetingImpl"6.url-pattern="/greeting"/>7.</endpoints>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 :)
http://java.dzone.com/articles/jax-ws-deployment-five-minute
No comments:
Post a Comment