概述


在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. ZOJ 3556 How Many Sets I

    How Many Sets I Time Limit: 2 Seconds      Memory Limit: 65536 KB Give a set S, |S| = n, then how ma ...

  2. Why to Not Not Start a Startup

    我花了周六,周日两天的时间,把这篇长文给阅读完了.很受益,改变了我的很多认知,也给我开拓了视野. 转载: Want to start a startup? Get funded by Y Combin ...

  3. MyBatis 系列五 之 延迟加载、一级缓存、二级缓存设置

    MyBatis的延迟加载.一级缓存.二级缓存设置 首先我们必须分清延迟加载的适用对象 延迟加载 MyBatis中的延迟加载,也称为懒加载,是指在进行关联查询时,按照设置延迟加载规则推迟对关联对象的se ...

  4. Codeforces Round #484 (Div. 2)

    题目链接:http://codeforces.com/contest/982 A. Row time limit per test:1 second memory limit per test:256 ...

  5. B. Complete the Word(Codeforces Round #372 (Div. 2)) 尺取大法

    B. Complete the Word time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  6. POJ 2431 Expedition (优先队列+贪心)

    题目链接 Description A group of cows grabbed a truck and ventured on an expedition deep into the jungle. ...

  7. 阅读关于DuReader:百度大规模的中文机器阅读理解数据集

    很久之前就得到了百度机器阅读理解关于数据集的这篇文章,今天才进行总结!.... 论文地址:https://arxiv.org/abs/1711.05073 自然语言处理是人工智能皇冠上的明珠,而机器阅 ...

  8. 【EverydaySport】健身笔记——动态牵拉

    动态牵拉,包含了动态和牵拉两个概念.动态牵拉要求牵拉的过程要伴随着走路,即行进中牵拉,动态牵拉不仅可以使得肌肉得到延展,还可以激活肌肉协同工作,发展协调性.灵活性.进行动态牵拉时每个动作要进行5~10 ...

  9. Phoenix批量修改数据

    很简单的一个东西,查了挺久的,浪费了很多的时间 直接用Upsert Into Select就可以了 例:把tables表中cloumn2列等于bbb的都改成aaa Upsert Into Table  ...

  10. FineReport——权限分配以及自定义首页

    权限分配可以有两种方法,第一种方法是根据部门职位分配权限,第二种是根据角色分配权限: FR自带有三个JQ对象,用以保存用户名参数/角色参数/部门参数——$fr_username/$fr_authori ...