`
eimhee
  • 浏览: 2115769 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

在Tomcat 上部署JAX-WS web services

阅读更多

Here’s a guide to show you how to deploy JAX-WS web services on Tomcat servlet container. See following summary steps of a web service deployment.

  1. Create a web service (of course).
  2. Create a sun-jaxws.xml, defines web service implementation class.
  3. Create a standard web.xml, defines WSServletContextListenerWSServlet and structure of a web project.
  4. Build tool to generate WAR file.
  5. Copy JAX-WS dependencies to “${Tomcat}/lib” folder.
  6. Copy WAR to “${Tomcat}/webapp” folder.
  7. Start It.

Directory structure of this example, so that you know where to put your files.

jaxws-deploy-tomcat--folder

1. WebServices

A simple JAX-WS hello world example.

File : HelloWorld.java

package com.mkyong.ws;
 
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.jws.soap.SOAPBinding.Style;
 
//Service Endpoint Interface
@WebService
@SOAPBinding(style = Style.RPC)
public interface HelloWorld{
 
	@WebMethod String getHelloWorldAsString();
 
}

File : HelloWorldImpl.java

package com.mkyong.ws;
 
import javax.jws.WebService;
 
//Service Implementation Bean
 
@WebService(endpointInterface = "com.mkyong.ws.HelloWorld")
public class HelloWorldImpl implements HelloWorld{
 
	@Override
	public String getHelloWorldAsString() {
		return "Hello World JAX-WS";
	}
}

Later, you will deploy this hello world web service on Tomcat.

2. sun-jaxws.xml

Create a web service deployment descriptor, which is also known as JAX-WS RI deployment descriptor – sun-jaxws.xml.

File : sun-jaxws.xml

<?xml version="1.0" encoding="UTF-8"?>
<endpoints
  xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime"
  version="2.0">
  <endpoint
      name="HelloWorld"
      implementation="com.mkyong.ws.HelloWorldImpl"
      url-pattern="/hello"/>
</endpoints>

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

Note
For detail endpoint attributes , see this article.

3. web.xml

Create a standard web.xml deployment descriptor for the deployment. Defines WSServletContextListener as listener class, WSServlet as your hello servlet.

File : web.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, 
Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_3.dtd">
 
<web-app>
    <listener>
        <listener-class>
                com.sun.xml.ws.transport.http.servlet.WSServletContextListener
        </listener-class>
    </listener>
    <servlet>
        <servlet-name>hello</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>hello</servlet-name>
        <url-pattern>/hello</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>120</session-timeout>
    </session-config>
</web-app>

4. WAR Content

Use Ant, Maven or JAR command to build a WAR file to include everything inside. The WAR content should look like this :

WEB-INF/classes/com/mkyong/ws/HelloWorld.class
WEB-INF/classes/com/mkyong/ws/HelloWorldImpl.class
WEB-INF/web.xml
WEB-INF/sun-jaxws.xml
Note
For those who are interested, here’s the Ant file to build this project and generate the WAR file.

 

File : build.xml

<project name="HelloWorldWS" default="dist" basedir=".">
    <description>
        Web Services build file
    </description>
  <!-- set global properties for this build -->
  <property name="src" location="src"/>
  <property name="build" location="build"/>
  <property name="dist"  location="dist"/>
  <property name="webcontent"  location="WebContent"/>
 
  <target name="init">
        <!-- Create the time stamp -->
        <tstamp/>
        <!-- Create the build directory structure used by compile -->
        <mkdir dir="${build}"/>
  </target>
 
  <target name="compile" depends="init"
  	description="compile the source " >
        <!-- Compile the java code from ${src} into ${build} -->
        <javac srcdir="${src}" destdir="${build}"/>
  </target>
 
  <target name="war" depends="compile"
  	description="generate the distribution war" >
 
	<!-- Create the war distribution directory -->
  	<mkdir dir="${dist}/war"/>
 
  	<!-- Follow standard WAR structure -->
  	<copydir dest="${dist}/war/build/WEB-INF/" src="${webcontent}/WEB-INF/" />
  	<copydir dest="${dist}/war/build/WEB-INF/classes/" src="${build}" />
 
	<jar jarfile="${dist}/war/HelloWorld-${DSTAMP}.war" basedir="${dist}/war/build/"/>
  </target>
 
</project>

5. JAX-WS Dependencies

By default, Tomcat does not comes with any JAX-WS dependencies, So, you have to include it manually.

1. Go here http://jax-ws.java.net/.
2. Download JAX-WS RI distribution.
3. Unzip it and copy following JAX-WS dependencies to Tomcat library folder “{$TOMCAT}/lib“.

  • jaxb-impl.jar
  • jaxws-api.jar
  • jaxws-rt.jar
  • gmbal-api-only.jar
  • management-api.jar
  • stax-ex.jar
  • streambuffer.jar
  • policy.jar

6. Deployment

Copy the generated WAR file to {$TOMCAT}/webapps/ folder and start the Tomcat server.

For testing, you can access this URL : http://localhost:8080/HelloWorld/hello, if you see following page, it means web services are deploy successfully.

jaxws-deploy-tomcat--example

Download Source Code

Download It – JAX-WS-Deploy-To-Tomcat-Example.zip (13KB)

 

分享到:
评论

相关推荐

    webService部署tomcat需要的jax-ws jar包

    webService部署tomcat需要的jax-ws 的完整jar包

    jax-ws webservice demo

    基于jax-ws 实现的web service client和server端的demo程序。 注:如果使用的是 myeclipse 时 server 部署到tomcat 启动的时候会报错 解决办法:找到myeclipse安装目录下的 plugins 目录里 查找 webservices-rt.jar,...

    2012 - Java 7 JAX-WS Web Services - Packtpub

    Develop Java 7 JAX-WS web services using the NetBeans IDE and Oracle GlassFish server End-to-end application which makes use of the new clientjar option in JAX-WS wsimport tool Packed with ample ...

    JAX-WS Web service

    JAX-WS Web service 开发初步

    jax-ws创建webservice

    利用myeclipse创建的 jax-ws demo

    MyEclipse8_0中使用 JAX-WS 部署 WebService 实例

    MyEclipse8_0中使用 JAX-WS 部署 WebService 实例 - 外衣 - 博客频道 - CSDN_NET.mht

    学习JAX-WSWebService开发

    学习JAX-WSWebService开发相关文档及Myeclipse开发方法。

    JAX-WS自学笔记

    JAX-WS自学笔记 本人自学JAX-WS笔记和简单例子,文档标题结构如下: JAX-WS使用教程 1、JAX-WS概述 2、创建Web Service 2.1 从java开始 2.1.1 运行wsgen 2.1.2 生成的WSDL和XSD 2.1.3 目录结构 2.2 从WSDL...

    jax-ws发布webservice

    以jdk1.6以上自带的jax-ws来发布webservice,压缩包里包含服务端和客户端,下载导入即可启动运行测试,有疑问的话欢迎咨询哈

    JAX-WS 2.2 RI所有相关jar包

    JAX-WS 2.2 RI 所包含的JAR包集合,包含25个JAR包,列表如下: FastInoset.jar gmbal-api-only.jar ha-api.jar javax.annotation.jar javax.mail_1.4.jar jaxb-api.jar jaxb-impl.jar jaxb-xjc.jar jaxws-api...

    Jax-ws所需要的JAR包

    亲测可用,Jax-ws所需要的JAR包,拷贝到tomcat安装路径的lib里,实现了webservice发布到tomcat,赞!

    metro-jax-ws-master

    The Java API for XML Web Services (JAX-WS) is a Java programming language API for creating web services, particularly SOAP services. JAX-WS is one of the Java XML programming APIs. It's a part of the ...

    JAX-WS_WebService.rar

    JAX-WS方式开发和部署webservice应用,JAX-WS方式开发和部署webservice应用,JAX-WS方式开发和部署webservice应用,JAX-WS方式开发和部署webservice应用,JAX-WS方式开发和部署webservice应用

    JAX-WS在Tomcat中发布服务

    JAX-WS在Tomcat中发布服务实例,同时在Handler中实现简单的授权校验。

    jax-ws 方式发布web Service 后台用Hibernate实现,前端.NET通过引用服务方式实现

    rar中包含整个项目的源码和数据库生成脚本,采用jax-ws发布Web Service服务,支持java客户端和.Net客户端调用,数据库采用oracle10g,里面有创建数据库脚本文件createTable_Oracle10g.sql,由于Hibernate映射表中会...

    JAX-WS2.0 API

    JAX-WS2.0 API

    JAX-WS开发的文件生成与部署相关全视频过程

    如果基于一个JAX-WS进行WebService开发,有很多教程,但是具体怎么更自动地生成一些文件,实现客户端与服务端的交互,都讲得不大清楚,为了让大家更方便地部署,我将服务端、客户端文件的生成与部署全过程以及测试...

    Jax-WS 简单实例

    Jax-WS的简单实例 Jax-WS的简单实例

    jax-ws webservice简单demo

    jax-ws webservice完整demo,包含所有jax-ws 2.2jar包。

    jax-rs jax-ws所需包,亲测可用

    javax.xml.ws.Service 报错需要的包,亲测可以用,直接下载在ide里buildpath一下就可以,四个jar包 ,整合了其他的jar所以配置简单

Global site tag (gtag.js) - Google Analytics