jdk1.8使用内置JAX-WS搭建webservice服务
环境说明:
1、jdk为64位1.8 2、win10操作系统 3、使用eclipse IDE编辑器,安装jetty,并配置Service
具体操作步骤:
- 1、搭建环境,创建动态网站项目,model Version 2.5版本,3.0好像报错
- 2、创建包service,service.imp,记得service别写成serivce了!!!
- 3、创建SayHiService接口,创建SayHiServiceImp实现类,具体代码不贴出了,可以到下面地址下载整体的项目包
- 4、创建sun-jaxws.xml和修改web.xml增加相应代码 以上的是增加的,具体代码里已经标注了,在一个要注意url-pattern,sun-jaxws和web.xml一定要一样的,包括全包名
- 5、添加引用的包,例如:jaxws-rt.jar等
- 6、运行启动,右击项目-》,Run-jetty,访问:http://localhost:8080/test/service/sayHi?wsdl
项目源码下载地址:
http://yunpan.cn/c6e8uLQ5DyYeM (提取码:983f)
项目功能部分截图:
遇到的问题错误:
1、错误三,在搭建完环境,创建完类库,运行代码时出错,由于错误太多只贴出一部分
2016-08-08 11:35:07.319:INFO::jetty-6.1.26 2016-08-08 11:35:07.728:WARN::Could not instantiate listener com.sun.xml.ws.transport.http.servlet.WSServletContextListener java.lang.ClassNotFoundException: com.sun.xml.ws.transport.http.servlet.WSServletContextListener at java.net.URLClassLoader.findClass(Unknown Source) at org.mortbay.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:392) at runjettyrun.ProjectClassLoader.loadClass(ProjectClassLoader.java:89) at org.mortbay.jetty.handler.ContextHandler.loadClass(ContextHandler.java:1102) at org.mortbay.jetty.webapp.WebXmlConfiguration.initListener(WebXmlConfiguration.java:630) at org.mortbay.jetty.webapp.WebXmlConfiguration.initWebXmlElement(WebXmlConfiguration.java:368) at org.mortbay.jetty.webapp.WebXmlConfiguration.initialize(WebXmlConfiguration.java:289) at org.mortbay.jetty.webapp.WebXmlConfiguration.configure(WebXmlConfiguration.java:222) at org.mortbay.jetty.webapp.WebXmlConfiguration.configureWebApp(WebXmlConfiguration.java:180) at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1279) at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:518) at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:499) at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50) at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130) at org.mortbay.jetty.Server.doStart(Server.java:224) at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50) at runjettyrun.Bootstrap.main(Bootstrap.java:97) 2016-08-08 11:35:08.356:WARN::EXCEPTION ...... 2016-08-08 11:35:08.606:WARN::Failed startup of context org.mortbay.jetty.webapp.WebAppContext@6cd8737{/test,C:\Users\yang\workspace\test\WebContent} org.mortbay.util.MultiException[java.lang.NullPointerException, java.lang.NullPointerException, java.lang.NullPointerException] at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:707) at org.mortbay.jetty.servlet.Context.startContext(Context.java:140) at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1282) at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:518) at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:499) at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50) at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130) at org.mortbay.jetty.Server.doStart(Server.java:224) at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50) at runjettyrun.Bootstrap.main(Bootstrap.java:97) 2016-08-08 11:35:08.930:INFO::Started SelectChannelConnector@0.0.0.0:8080
解决:到https://jax-ws.java.net/下载jax-ws lib包,放到项目里,并导入项目。
参考文档:
http://www.cnblogs.com/adolfmc/p/4383091.html
http://blog.csdn.net/accountwcx/article/details/46884775
http://liugang594.iteye.com/blog/1387460
http://www.cnblogs.com/Johness/archive/2013/04/19/3030392.html
需要文件下载地址:
jaxws: http://repo.maven.apache.org/maven2/com/sun/xml/ws/jaxws-ri/2.2.10/jaxws-ri-2.2.10.zip
64-jdk: http://download.oracle.com/otn-pub/java/jdk/8u101-b13/jdk-8u101-windows-x64.exe?AuthParam=1470626220_130021c8ef040c2456d1d426448a68b2
32-jdk: http://sw.bos.baidu.com/sw-search-sp/software/11500c7bad2ed/jdk_8u101_windows_i586_8.0.1010.13.exe
jetty: http://repo1.maven.org/maven2/org/eclipse/jetty/jetty-distribution/8.1.19.v20160209/jetty-distribution-8.1.19.v20160209.zip
eclipse-64: http://ftp.jaist.ac.jp/pub/eclipse/technology/epp/downloads/release/neon/R/eclipse-jee-neon-R-win32-x86_64.zip