前言:
虽然构建本地的jax-ws的webservice很简单,但要部署到tomcat上要绕过点弯。
tomcat本身和jdk都没有jaw-ws的API,所以部署的时候需要额外做点事情,有两种选择
1、下载必要的jar库,JAX-WS RI,地址:https://jax-ws.java.net/
2、使用其他服务器,比如TomEE(tomcat的加强版)等。(未测试),可以参考:
Step by Step JAX-WS Web Services with Eclipse, TomEE, and Apache CXF
因为平时用tomcat比较多,就用第一种方式。
一、准备工作
下载jax-ws RI。
配置:根据文档,
To install on Tomcat
Set CATALINA_HOME to your Tomcat installation.
Run
ant install
This essentially copies lib/*.jar from the root of JAX-WS RI extracted bundle to $CATALINA_HOME/shared/lib
package org.ccnt.jax.web.client;
public class ClientMain {
public static void main(String[] args) {
HelloService service = new HelloService();
String response = service.getHelloPort().say("loull");
System.out.println(response);
}
}
五、总结下过程
Create a web service (of course).
Create a sun-jaxws.xml, defines web service implementation class.
Create a standard web.xml, defines WSServletContextListener, WSServlet and structure of a web project.
Build tool to generate WAR file.
Copy JAX-WS dependencies to “${Tomcat}/lib” folder.