标签:des style blog class code java
------------------------------------转---------------------------------
In this tutorial we are going to see how to deploy JAX-WS Web Services on Tomcat. For this tutorial we are going to use Eclipse Eclipse 4.3 Kepler, which will also help us to construct the necessary WAR file for the Web Application.
In order to deploy a Web Service on Tomcat one should follow these steps:
TOMCAT_HOME/lib
foldersun-jaxws.xml
to define the Web Service
implemenation class.web.xml
to describe the structure of the
web project.TOMCAT_HOME/webapps
folder.Tomcat will need some jars in order to deploy a JAX-WS Web Service. You have
to go to : http://jax-ws.java.net/ and download JAX-WS RI library.
Unzip the folder and copy the jars
in TOMCAT_HOME/lib
folder. If you don’t want to copy the
complete library these are the jars that are necessary:
gmbal-api-only.jar
jaxb-impl.jar
jaxws-api.jar
jaxws-rt.jar
management-api.jar
policy.jar
stax-ex.jar
streambuffer.jar
Open Eclipse IDE and go to File -> New -> Project -> Web -> Dynamic Web Project :
Then create a Project with name JAX-WS-Tomcat.
In order to create our Web Service Endpoint:
WebServiceInterface.java:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 |
package com.javacodegeeks.enterprise.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 WebServiceInterface { @WebMethod String printMessage(); } |
WebServiceImpl.java:
1
2
3
4
5
6
7
8
9
10
11
12
13 |
package com.javacodegeeks.enterprise.ws; import javax.jws.WebService; @WebService(endpointInterface = "com.javacodegeeks.enterprise.ws.WebServiceInterface" ) public
class WebServiceImpl implements WebServiceInterface{ @Override public
String printMessage() { return
"Hello from Java Code Geeks Server" ; } } |
Go to WebContent/WEB-INF
folder and create a new XML
file .This is a classic web.xml
file to deploy a Web
Service.
web.xml:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 |
<?xml version= "1.0"
encoding= "UTF-8" ?> <!DOCTYPE web-app PUBLIC "- //Sun Microsystems, Inc. //DTD Web Application 2.3//EN" <web-app> <listener> <listener- class > com.sun.xml.ws.transport.http.servlet.WSServletContextListener </listener- class > </listener> <servlet> <servlet-name>sayhello</servlet-name> <servlet- class > com.sun.xml.ws.transport.http.servlet.WSServlet </servlet- class > <load- on -startup>1</load- on -startup> </servlet> <servlet-mapping> <servlet-name>sayhello</servlet-name> <url-pattern>/sayhello</url-pattern> </servlet-mapping> <session-config> <session-timeout>30</session-timeout> </session-config> </web-app> |
You have to define the Service Endpoint Implementation class as the endpoint
of your project, along with the URL pattern of the Web Service. Go
to WebContent/WEB-INF
folder and create a new XML
file
sun-jaxws.xml:
1
2
3
4
5
6
7 |
<?xml version= "1.0"
encoding= "UTF-8" ?> <endpoints xmlns= "http://java.sun.com/xml/ns/jax-ws/ri/runtime" version= "2.0" > <endpoint name= "WebServiceImpl" implementation= "com.javacodegeeks.enterprise.ws.WebServiceImpl" url-pattern= "/sayhello"
/> </endpoints> |
You can find more info in the JAX-WS Documentation.
This is the Eclipse Project Structure:
Now, go to the Package explorer and Right Click on the Project -> Export -> WAR file :
Now you have to save the WAR file:
After exporting the WAR file you have to copy it
to TOMCAT_HOME/webapps
folder. There are quite a few ways
to create the WAR file. You can use Maven, Ant, or even the jar
command line
tool.
Now you can start Tomcat. Then put the following URL in your Web Browser :
If everything is ok this is what you should get:
Now you can create a consumer of the Web Service like we did in previous tutorials like JAX-WS Hello World Example – RPC Style.
This was an example on how to deploy JAX-WS Web Services on Tomcat. Download the Eclipse Project of this example : JAX-WS-Tomcat.zip
jax-ws tomcat demo,布布扣,bubuko.com
标签:des style blog class code java
原文地址:http://www.cnblogs.com/shanyangmanbu/p/3719756.html