jax-ws tomcat demo

------------------------------------转---------------------------------

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:

  1. Frist of all you have to download Apache Tomcat.

  2. Copy JAX-WS RI jars
    in TOMCAT_HOME/lib folder

  3. Create a Dynamic Web Application in Eclipse.

  4. Create a JAX-WS Endpoint (Web Service interface, and Web Service
    implementation).

  5. Create a sun-jaxws.xml to define the Web Service
    implemenation class.

  6. Create a web.xml to describe the structure of the
    web project.

  7. Export WAR file from Eclipse and copy it
    to TOMCAT_HOME/webapps folder.

  8. Start Tomcat.

1. JAX-WS Dependencies in Tomcat

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

2. Create a Dyncamic Web Project in Eclipse

Open Eclipse IDE and go to File -> New -> Project -> Web ->
Dynamic Web Project :

Then create a Project with name JAX-WS-Tomcat.

3. Service Endpoint

In order to create our Web Service Endpoint:

  • First you have to create a Web Service Endpoint Interface. This interface
    will contain the declerations of all the methods you want to include in the
    Web Service.

  • Then you have to create a class that actually implements the above
    interface, which will be your Endpoint implementation.

Web Service Endpoint Interface

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();

}

  

Web Service Endpoint Implementation

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";

    }

}

  

4. Create the web.xml file

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"

"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>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>

  

5. Create sun-jaxws.xml file.

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:

6. Export WAR file

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 MavenAnt, or even the jar command line
tool.

Now you can start Tomcat. Then put the following URL in your Web Browser
:






1 http://localhost:8080/JAX-WS-Tomcat/sayhello

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

时间: 2024-09-27 18:31:38

jax-ws tomcat demo的相关文章

webmagic采集CSDN的Java_WebDevelop页面

项目中使用到了webmagic,采集论坛一类的页面时需要一些特殊的配置.在此记录一下 先来看看我要采集的页面 点击第2页可以看到它的url是http://bbs.csdn.net/forums/Java_WebDevelop?page=2 点击尾页可以看到它的url是http://bbs.csdn.net/forums/Java_WebDevelop?page=758 也就是说我们需要采集的范围是从2到758页 这样我们就可以通过自己拼接一个url来模拟所有 的连接了代码如下: <span st

Web Service 那点事儿(2)—— 使用 CXF 开发 SOAP 服务

选框架犹如选媳妇,选来选去,最后我还是选了“丑媳妇(CXF)”,为什么是它?因为 CXF 是 Apache 旗下的一款非常优秀的 WS 开源框架,具备轻量级的特性,而且能无缝整合到 Spring 中. 其实 CXF 是两个开源框架的整合,它们分别是:Celtix 与 XFire,前者是一款 ESB 框架,后者是一款 WS 框架.话说早在 2007 年 5 月,当 XFire 发展到了它的鼎盛时期(最终版本是 1.2.6),突然对业界宣布了一个令人震惊的消息:“XFire is now CXF”,

Java 5 、6、 7中新特性

JDK5新特性(与1.4相比)[转] 1 循环 for (type variable : array){ body} for (type variable : arrayList){body} 而1.4必须是: for (int i = 0; i < array.length; i++){ type variable = array[i];    body} for (int i = 0; i < arrayList.size(); i++){type variable = (type) ar

spring mvc4使用及json 日期转换解决方案

spring mvc使用注解方式配制,以及对rest风格的支持,真是完美致极.下面将这两天研究到的问题做个总结,供参考.1.request对象的获取方式1:在controller方法上加入request参数,spring会自动注入,如:public String list(HttpServletRequest request,HttpServletResponse response)方式2:在controller类中加入@Resource private HttpServletRequest r

[UI]Flat UI - Free Boorstrap Framework and Theme

---------------------------------------------------------------------------------------------------------- Flat UI Free - Design Framework (html/css3/less/js). Flat UI is based on Bootstrap, a comfortable, responsive, and functional framework that si

怎样用命令行管理SharePoint Feature?

普通情况下对IT管理者来说.在SharePoint Farm中维护Feature,更喜欢使用命令行实现,这样能够省去登录到详细网站的操作. 比方IT接到end user的一个需求,要开启Site Collection Feature,假设直接操作就要登录site collection-> Site Setting找到Feature点击运行enable\disable.要是使用命令行直接输入命令和站点会更快捷. 以下我们就以SharePoint2013为例,看下对于Feature的enable.d

dubbo简单配置与使用

dubbo简介 随着互联网的发展,网站应用的规模不断扩大,常规的垂直应用架构已无法应对,分布式服务架构以及流动计算架构势在必行,亟需一个治理系统确保架构有条不紊的演进. 单一应用架构 当网站流量很小时,只需一个应用,将所有功能都部署在一起,以减少部署节点和成本. 此时,用于简化增删改查工作量的 数据访问框架(ORM) 是关键. 垂直应用架构 当访问量逐渐增大,单一应用增加机器带来的加速度越来越小,将应用拆成互不相干的几个应用,以提升效率. 此时,用于加速前端页面开发的 Web框架(MVC) 是关

WebSocket基于javaweb+tomcat的简易demo程序

由于项目需要,前端向后台发起请求后,后台需要分成多个步骤进行相关操作,而且不能确定各步骤完成所需要的时间 倘若使用ajax重复访问后台以获取实时数据,显然不合适,无论是对客户端,还是服务端的资源很是浪费 这种情况下,WebSocket能够解决此问题 它不像普通的http请求或者ajax访问,返回相应的结果就关闭了连接 WebSocket在个人浅薄的知识看来是属于长连接,能保持连接,随时收发数据 所以对WebSocket进行了初步了解,并按照相关的教程尝试做了一个简易demo 首先需要了解的是,W

dubbo开发环境搭建与tomcat集成、DEMO示例(最完整版本、带管理控制台、监控中心、zookeeper)

以windows为例,linux基本相同,开发环境一般linux,个人环境一般windows(如果不开额外vm的话). 示例以dubbo官方自带demo为例子,进行整合和稍加修改测试. 0.dubbox是dubbo的当当fork版本,特性上最主要是集成了REST.就核心功能而言,dubbo和大部分其他rpc框架比如spring cloud类似,由客户端.服务端.服务注册与发现中心.监控中心以及管理中心组成.如下: 1.安装zookeeper,从https://zookeeper.apache.o