JDK中已经内置了Webservice发布,不过要用Tomcat等Web服务器发布WebService,还需要用第三方Webservice框架。Axis2和CXF是目前最流行的Webservice框架,这两个框架各有优点,不过都属于重量级框架。 JAX-WS RI是JAX WebService参考实现。相对于Axis2和CXF,JAX-WS RI是一个轻量级的框架。虽然是个轻量级框架,JAX-WS RI也提供了在Web服务器中发布Webservice的功能。官网地址https://jax-ws.java.net/。下面用JAX-WS RI在Tomcat中发布WebService。

服务端

1、新建一个Maven Web项目,在项目中添加JAX-WS RI引用,pom.xml配置文件如下:

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <project xmlns="http://maven.apache.org/POM/4.0.0"
 3          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 5     <modelVersion>4.0.0</modelVersion>
 6 
 7     <groupId>top.jimc</groupId>
 8     <artifactId>wsi</artifactId>
 9     <version>1.0-SNAPSHOT</version>
10     <packaging>war</packaging>
11 
12     <properties>
13         <junit.version>4.12</junit.version>
14         <jaxws-rt.version>2.2.10</jaxws-rt.version>
15     </properties>
16 
17     <dependencies>
18         <!-- junit -->
19         <dependency>
20             <groupId>junit</groupId>
21             <artifactId>junit</artifactId>
22             <version>${junit.version}</version>
23             <scope>test</scope>
24         </dependency>
25 
26         <!-- JAXWS-RI -->
27         <dependency>
28             <groupId>com.sun.xml.ws</groupId>
29             <artifactId>jaxws-rt</artifactId>
30             <version>${jaxws-rt.version}</version>
31         </dependency>
32     </dependencies>
33 
34     <build>
35         <plugins>
36             <!-- 配置控制jdk版本的插件 -->
37             <plugin>
38                 <groupId>org.apache.maven.plugins</groupId>
39                 <artifactId>maven-compiler-plugin</artifactId>
40                 <version>3.7.0</version>
41                 <configuration>
42                     <source>1.8</source>
43                     <target>1.8</target>
44                     <encoding>utf-8</encoding>
45                 </configuration>
46             </plugin>
47         </plugins>
48     </build>
49 
50 </project>
View Code

相关文章: