概述


在web项目中发布基于jaxws的webservice。
参考文章说,如果不是servlet3.0及以上,需要配置servlet,请注意。
 
servlet3.0的web.xml的框架:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0" metadata-complete="false">
<display-name>Archetype Created Web Application</display-name>
</web-app>
Maven依赖

<!-- JAXWS-RI -->
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>2.2.10</version>
</dependency>
依赖分析结果:
[INFO] \- com.sun.xml.ws:jaxws-rt:jar:2.2.10:compile
[INFO] +- javax.xml.bind:jaxb-api:jar:2.2.12-b140109.1041:compile
[INFO] +- javax.xml.ws:jaxws-api:jar:2.2.11:compile
[INFO] +- javax.xml.soap:javax.xml.soap-api:jar:1.3.7:compile
[INFO] +- javax.annotation:javax.annotation-api:jar:1.2:compile
[INFO] +- javax.jws:jsr181-api:jar:1.0-MR1:compile
[INFO] +- com.sun.xml.bind:jaxb-core:jar:2.2.10-b140802.1033:compile
[INFO] +- com.sun.xml.bind:jaxb-impl:jar:2.2.10-b140802.1033:compile
[INFO] +- com.sun.xml.ws:policy:jar:2.4:compile
[INFO] +- org.glassfish.gmbal:gmbal-api-only:jar:3.1.0-b001:compile
[INFO] | \- org.glassfish.external:management-api:jar:3.0.0-b012:compile
[INFO] +- org.jvnet.staxex:stax-ex:jar:1.7.7:compile
[INFO] +- com.sun.xml.stream.buffer:streambuffer:jar:1.5.3:compile
[INFO] +- org.jvnet.mimepull:mimepull:jar:1.9.4:compile
[INFO] +- com.sun.xml.fastinfoset:FastInfoset:jar:1.2.13:compile
[INFO] +- org.glassfish.ha:ha-api:jar:3.1.9:compile
[INFO] +- com.sun.xml.messaging.saaj:saaj-impl:jar:1.3.25:compile
[INFO] +- org.codehaus.woodstox:woodstox-core-asl:jar:4.2.0:runtime
[INFO] +- org.codehaus.woodstox:stax2-api:jar:3.1.1:runtime
[INFO] \- com.sun.org.apache.xml.internal:resolver:jar:20050927:compile
不使用Maven,需要人工导入上述jar包;可以尝试在http://mvnrepository.com/中获取。

服务实现


假设你已经清楚如何使用jaxws实现webservice,这里仅提供简略的说明和代码。
这里写一个简单的服务,返回“hello, jaxws!”字符串。

服务接口

IHelloJAXWSService.java
package cn.ljl.baseframe.test.jaxws;
import javax.jws.WebResult;
import javax.jws.WebService;
@WebService
public interface IHelloJAXWSService {
@WebResult(name = "helloWorld")
public String getHelloWord();
}

服务实现类

HelloJAXWSServiceImpl.java
package cn.ljl.baseframe.test.jaxws;
import javax.jws.WebService;
@WebService(endpointInterface = "cn.ljl.baseframe.test.jaxws.IHelloJAXWSService")
public class HelloJAXWSServiceImpl implements IHelloJAXWSService {
@Override
public String getHelloWord() {
String helloWorld = "hello, jaxws!";
return helloWorld;
}
}

配置endpoints


在WEB-INF目录下,添加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">
<!-- 服务路径http://网站路径/services/hello -->
<endpoint name="hello"
implementation="cn.ljl.baseframe.test.jaxws.HelloJAXWSServiceImpl"
url-pattern="/services/hello" />
</endpoints>
注意:网上多个文章都要求这个文件是UTF-8编码,没有测试是否必须。

测试


在web项目中发布jaxws的更多相关文章

  1. day63-webservice 06.在web项目中发布以类的形式发布webservice

    真正用的时候都是需要部署在WEB服务器里面. 不能写主函数来发布了,需要借助于我们WEB. 4.配置web.xml, <!DOCTYPE web-app PUBLIC "-//Sun ...

  2. JAVA WEB项目中各种路径的获取

    JAVA WEB项目中各种路径的获取 标签: java webpath文件路径 2014-02-14 15:04 1746人阅读 评论(0) 收藏 举报  分类: JAVA开发(41)  1.可以在s ...

  3. java web项目中 获取resource路径下的文件路径

    public GetResource{ String path = GetResource.class.getClassLoader().getResource("xx/xx.txt&quo ...

  4. 转 web项目中的web.xml元素解析

    转 web项目中的web.xml元素解析 发表于1年前(2014-11-26 15:45)   阅读(497) | 评论(0) 16人收藏此文章, 我要收藏 赞0 上海源创会5月15日与你相约[玫瑰里 ...

  5. Log4j2在WEB项目中配置

    最近决定在新WEB项目中使用新的日志系统Log4j2. 官方介绍和学习文档网址为http://logging.apache.org/log4j/2.x/ 首先在WEB项目中引入以下几个jar包: ① ...

  6. (转)关于java和web项目中的相对路径问题

    原文:http://blog.csdn.net/yethyeth/article/details/1623283 关于java和web项目中的相对路径问题 分类: java 2007-05-23 22 ...

  7. extjs6整合到web项目中

    最近有一个项目需要应用extjs作为前端界面,因此研究了一下如何将extjs 6引入到项目中.以下是操作步骤 extjs6下载地址 extjs 6有gpl版本的,下载地址https://www.sen ...

  8. web项目中获取各种路径的方法

    ~Apple   web项目中各种路径的获取 1.可以在servlet的init方法里 String path = getServletContext().getRealPath("/&qu ...

  9. 【适合公司业务】全网最详细的IDEA里如何正确新建【普通或者Maven】的Java web项目并发布到Tomcat上运行成功【博主强烈推荐】(类似eclipse里同一个workspace下【多个子项目】并存)(图文详解)

    不多说,直接上干货! 首先,大家要明确,IDEA.Eclipse和MyEclipse等编辑器之间的新建和运行手法是不一样的. 如果是在Myeclipse里,则是File -> new -> ...

随机推荐

  1. sudo: /usr/libexec/sudo/sudoers.so must be only be writable by owne

    1. chmod 644 sudoers.so 2. pkexec chmod 0440 /etc/sudoers

  2. 【NOIP】提高组2013 火柴排队

    [题意]两列n个火柴,分别有高度ai和bi(同一列高度互不相同),每次可以交换一列中的两个相邻火柴,定义距离为∑(ai-bi)^2,求使距离最小的最少交换次数,n<=10^5. [算法]逆序对 ...

  3. Java 对象排序详解

    很难想象有Java开发人员不曾使用过Collection框架.在Collection框架中,主要使用的类是来自List接口中的ArrayList,以及来自Set接口的HashSet.TreeSet,我 ...

  4. 【洛谷 P3809】 【模板】后缀排序

    题目链接 先占个坑,以后再补. \(SA\)的总结肯定是要写的. 等理解地深入一点再补. #include <cstdio> #include <cstring> const ...

  5. div+css实现表头固定内容滚动表格

    <div class="m-demo"> <table> <thead> <tr><th>定宽a</th>& ...

  6. 【Python学习笔记】异常处理try-except

    Python异常处理 我们一般使用try-except语句来进行异常处理. 使用except Exception as err可以统一捕捉所有异常,而也可以分开处理单个异常. # 分开捕捉单个异常 t ...

  7. selenium===splinter模块和selenium异曲同工

    学习文档: http://splinter.readthedocs.io/en/latest/ 安装以后用它来实现163邮箱的登陆操作:*和selenium一样,splinter同样需要对frame进 ...

  8. monkey测试===修改adb的默认端口

    最近电脑上由于公司系统的原因,adb的端口被占用了,但是占用端口的进程是必须启动的,不能被杀死,在网上找了很多办法,大家都是说杀死占用端口的进程.这个方法并不适用我,所以在此给大家一个新的方法.新建一 ...

  9. 蓝屏代码0X0000007B可能是SATA mode问题

    Win7蓝屏代码0X0000007B可能是硬盘模式的问题,我进入BIOS把SATA的mode从Enhanced改为Compatible(及IDE兼容模式)结果系统可以顺利启动没有问题.       从 ...

  10. Web开发中,页面渲染方案

    转载自:http://www.jianshu.com/p/d1d29e97f6b8 (在该文章中看到一段感兴趣的文字,转载过来) 在Web开发中,有两种主流的页面渲染方案: 服务器端渲染,通过页面渲染 ...