简体   繁体   English

无法在Apache Tomcat上运行JAX-WS Java Web Service

[英]Cannot run JAX-WS Java Web Service on Apache Tomcat

Summary 摘要

I've been tasked to write a Java web service to integrate two disparate systems in our enterprise environment. 我的任务是编写一个Java Web服务来在我们的企业环境中集成两个不同的系统。 Since I'm actually an experienced C#.NET MVC developer and only consider myself intermediate at Java, I began by searching for "Java Web Service Tutorials". 由于我实际上是一位经验丰富的C#.NET MVC开发人员,并且只考虑自己是Java的中间人,因此我开始搜索“Java Web Service Tutorials”。 I am trying to run this common tutorial , but I'm unable to run the tutorial service due to an HTTP 404 error. 我正在尝试运行此常见教程 ,但由于HTTP 404错误我无法运行教程服务。

Process 处理

I'm using the Java Web Application template in Netbeans 8.0.2 . 我在Netbeans 8.0.2中使用Java Web应用程序模板。 I used JDK 1.6.0.25 to compile the tutorial (since the eventual service I need to write will need this Java version to be compatible with some other JARs I'll be using). 我使用JDK 1.6.0.25来编译教程(因为我需要编写的最终服务需要这个Java版本与我将使用的其他一些JAR兼容)。 Everything compiles to a WAR file just fine. 一切都编译成WAR文件就好了。

I then deployed the WAR file by loading the server's Tomcat Manager GUI and using the WAR file to deploy feature. 然后,我通过加载服务器的Tomcat Manager GUI并使用WAR文件部署功能来部署WAR文件 When I do so, the WAR file is copied, and the application starts. 当我这样做时,将复制WAR文件,并启动应用程序。 However, when I attempt to access the service via the link " http://localhost:8080/HelloWorld/hello " from the tutorial , the service returns a 404 error. 但是,当我尝试通过教程中的http:// localhost:8080 / HelloWorld / hello ”链接访问该服务时,该服务返回404错误。

Server Environment 服务器环境

  • Oracle Enterprise Linux distro, version 3.8.13-44.1.1.el6uek.x86_64 Oracle Enterprise Linux发行版,版本3.8.13-44.1.1.el6uek.x86_64
  • Apache Tomcat 6.0.24 Apache Tomcat 6.0.24
  • JVM 1.7.0_75-mockbuild_2015_01_20_16_42-b00 JVM 1.7.0_75-mockbuild_2015_01_20_16_42-b00

If the advice is that I need to change the Java or Tomcat versions or platforms, I need to know that as well since I have little experience with these technologies. 如果建议是我需要更改Java或Tomcat版本或平台,我也需要知道,因为我对这些技术的经验很少。 However, I may not be able to change all the factors due to limitations with my Linux distro (per my server admin). 但是,由于Linux发行版的限制(我的服务器管理员),我可能无法更改所有因素。

Things I've tried (in order): 我尝试过的事情(按顺序):

Setup a Local Tomcat Server on Windows 在Windows上设置本地Tomcat服务器

I installed a local Tomcat Server on my Windows 7 laptop. 我在Windows 7笔记本电脑上安装了本地Tomcat服务器。 Since the Linux server is running Java 1.7.0.75, I installed a matching Windows version of JRE 1.7.0.75 from Oracle's support page . 由于Linux服务器运行的是Java 1.7.0.75,因此我从Oracle的支持页面安装了匹配的Windows版本的JRE 1.7.0.75 I then downloaded Apache Tomcat 6.0.24 Windows Service from their archives and installed it successfully, using the JRE 1.7.0.75 and local port 1985 (to separate it from the GlassFish local server used within Netbeans). 然后我从他们的档案中下载了Apache Tomcat 6.0.24 Windows服务并使用JRE 1.7.0.75和本地端口1985成功安装它(将它与Netbeans中使用的GlassFish本地服务器分开)。

Just as on the Linux server, my local Tomcat server couldn't start the tutorial. 就像在Linux服务器上一样,我的本地Tomcat服务器无法启动教程。 Manually clicking the start command link gives me the message "FAIL - Application at context path /com.mkyong.ws could not be started". 手动单击启动命令链接给我的消息“失败 - 无法启动上下文路径/com.mkyong.ws上的应用程序”。 My local server's logs don't show anything about that application failing to start either. 我的本地服务器的日志没有显示该应用程序无法启动的任何内容。

Adding JAX-WS RI JAR files to {$Tomcat}/lib 将JAX-WS RI JAR文件添加到{$ Tomcat} / lib

Per section 5 on the tutorial mentioned above , I then added the indicated JAR files to the server's {$Tomcat}/lib folder and restarted the server. 根据上面提到教程的第5节,我然后将指示的JAR文件添加到服务器的{$ Tomcat} / lib文件夹并重新启动服务器。 This time, the application started , but I still couldn't access the service. 这次, 应用程序启动了 ,但我仍然无法访问该服务。 The link " http://localhost:8080/HelloWorld/hello " from the tutorial returns a 404 error. 教程中的链接“ http:// localhost:8080 / HelloWorld / hello ”返回404错误。 I even tried copying the entire JAX-WS RI/lib folder to the {$Tomcat}/lib directory with no changes, so I backed out this change. 我甚至尝试将整个JAX-WS RI / lib文件夹复制到{$ Tomcat} / lib目录而没有任何更改,因此我撤销了此更改。

For reference, here's a list of the files I've copied: 作为参考,这是我复制的文件列表:

  • gmbal-api-only.jar gmbal-API only.jar
  • ha-api.jar HA-api.jar文件
  • jaxb-core.jar JAXB-core.jar添加
  • jaxb-impl.jar JAXB - impl.jar中
  • jaxws-api.jar JAXWS-api.jar文件
  • jaxws-rt.jar JAXWS-的rt.jar
  • management-api.jar 管理-api.jar文件
  • policy.jar policy.jar
  • stax-ex.jar STAX-ex.jar
  • streambuffer.jar streambuffer.jar

Enabling DEBUG mode in the local Tomcat Server 在本地Tomcat服务器中启用DEBUG模式

I un-deployed the WAR file. 我取消部署了WAR文件。 Using the Apache Tomcat Monitor , I stopped the service, deleted the existing logs, enabled the DEBUG logging level, and restarted the service. 使用Apache Tomcat Monitor ,我停止了服务,删除了现有日志,启用了DEBUG日志记录级别,并重新启动了服务。 I then re-deployed the tutorial WAR file. 然后我重新部署了教程WAR文件。 I again saw it didn't start, and then I opened all the log files. 我再次看到它没有启动,然后我打开了所有日志文件。 There is not even a mention of the failure to access the service, but perhaps 404 errors aren't logged. 甚至没有提到访问服务的失败,但可能没有记录404错误。

Running the service using the Netbeans-embedded Glassfish server 使用Netbeans嵌入式Glassfish服务器运行服务

When I first created the Web Application, Netbeans offered to set me up with a local Glassfish server. 当我第一次创建Web应用程序时,Netbeans提供了一个本地Glassfish服务器。 I accepted, and I set everything up with defaults. 我接受了,我用默认设置了一切。 When I try to run the tutorial against this server, I cannot access the service. 当我尝试针对此服务器运行教程时,我无法访问该服务。 The link " http://localhost:8080/HelloWorld/hello " from the tutorial still returns a 404 error. 教程中的链接“ http:// localhost:8080 / HelloWorld / hello ”仍然返回404错误。

Researching other posts and tutorials 研究其他帖子和教程

Here are some other StackOverflow posts and websites I've reviewed without finding a resolution: 以下是我查看的其他一些StackOverflow帖子和网站,但未找到解决方案:

Questions I'm Pondering 我正在考虑的问题

  • Is there something wrong with the code in the tutorial? 教程中的代码有问题吗? (Doesn't seem likely since from the comments others have had success.) (从其他人的评论中看起来似乎没有成功。)
  • Is there a significant difference in the versions of Java or Tomcat he's using in the tutorial? 他在本教程中使用的Java或Tomcat版本是否存在显着差异? (He doesn't give an versions of Java or Tomcat.) (他没有提供Java或Tomcat的版本。)
  • Should I run local Tomcat against a JDK instead of a JRE? 我应该针对JDK而不是JRE运行本地Tomcat吗?
  • Should the tutorial be compiled against the same JDK as Tomcat is using? 是否应该根据Tomcat使用的相同JDK编译教程? (I hope not as this would seem very limiting...) (我希望不会因为这似乎非常有限......)
  • Can I even run JAX-WS in Tomcat? 我甚至可以在Tomcat中运行JAX-WS吗? (Based on pages like http://tomee.apache.org/apache-tomee.html , it seems like the base TOmcat might not even support JAX-WS? Again, just my limited experience.) (基于像http://tomee.apache.org/apache-tomee.html这样的页面,看起来基础TOmcat可能甚至不支持JAX-WS?再次,仅仅是我有限的经验。)

I'd appreciate any troubleshooting guidance anyone can offer. 我很感激任何人都能提供的任何故障排除指导。 Thank you in advance for the help! 提前感谢您的帮助!

UPDATE #1 更新#1

Per the request of @NIKETBHANDARY, I stopped the service, deleted the logs, restarted the service, and browsed in Chrome to localhost:1985/helloworld/hello - still getting the 404 error. 根据@NIKETBHANDARY的请求,我停止了服务,删除了日志,重新启动了服务,并在Chrome浏览器中浏览到localhost:1985 / helloworld / hello - 仍然收到404错误。 I then opened the catalina.log file, but it's completely empty. 然后我打开了catalina.log文件,但它完全是空的。 Only jakarta_service.log has any log entries, and all are about the service starting. 只有jakarta_service.log有任何日志条目,并且所有日志条目都与服务启动有关。 I also verified that the logging level is set to debug . 我还验证了日志记录级别设置为debug What else can I change to get additional log messages? 还有什么可以更改以获取其他日志消息?

I also ran a search for "com.mkyong" in the entire Tomcat directory. 我还在整个Tomcat目录中搜索了“com.mkyong”。 Only the webapp WAR file, webapps/../META-INF/context.xml, webapps/../WEB-INF/sun-jaxws.xml, and /conf/cataline/localhost/com.mkyong.we.xml files returned any hits. 只有webapp WAR文件,webapps /../ META-INF / context.xml,webapps /../ WEB-INF / sun-jaxws.xml和/conf/cataline/localhost/com.mkyong.we.xml文件返回任何命中。 Nothing in any logs. 任何日志都没有。 Could that indicate that this is a configuration problem? 这可能表明这是配置问题吗?

UPDATE #2 更新#2

Apparently, Tomcat doesn't flush its log messages fully until the thread closes as the service shuts down (probably due to the logging configuration). 显然,Tomcat不会完全刷新其日志消息,直到线程在服务关闭时关闭(可能是由于日志记录配置)。 As such, I stopped the service which flushed the log files. 因此,我停止了刷新日志文件的服务。 Here's the entire contents of the catalina.log file (which does contain a reference to com.mkyong): 这是catalina.log文件的全部内容(它包含对com.mkyong的引用):

Aug 17, 2015 9:51:17 PM org.apache.catalina.core.AprLifecycleListener init
INFO: Loaded APR based Apache Tomcat Native library 1.1.19.
Aug 17, 2015 9:51:17 PM org.apache.catalina.core.AprLifecycleListener init
INFO: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
Aug 17, 2015 9:51:19 PM org.apache.coyote.http11.Http11AprProtocol init
INFO: Initializing Coyote HTTP/1.1 on http-1985
Aug 17, 2015 9:51:19 PM org.apache.coyote.ajp.AjpAprProtocol init
INFO: Initializing Coyote AJP/1.3 on ajp-8009
Aug 17, 2015 9:51:19 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 2121 ms
Aug 17, 2015 9:51:19 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Aug 17, 2015 9:51:19 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.24
Aug 17, 2015 9:51:19 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor com.mkyong.ws.xml
Aug 17, 2015 9:51:20 PM com.sun.xml.ws.transport.http.servlet.WSServletContextListener contextInitialized
INFO: WSSERVLET12: JAX-WS context listener initializing
Aug 17, 2015 9:51:22 PM com.sun.xml.ws.transport.http.servlet.WSServletDelegate <init>
INFO: WSSERVLET14: JAX-WS servlet initializing
Aug 17, 2015 9:51:22 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor host-manager.xml
Aug 17, 2015 9:51:22 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor manager.xml
Aug 17, 2015 9:51:22 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory docs
Aug 17, 2015 9:51:22 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory examples
Aug 17, 2015 9:51:22 PM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory ROOT
Aug 17, 2015 9:51:22 PM org.apache.coyote.http11.Http11AprProtocol start
INFO: Starting Coyote HTTP/1.1 on http-1985
Aug 17, 2015 9:51:22 PM org.apache.coyote.ajp.AjpAprProtocol start
INFO: Starting Coyote AJP/1.3 on ajp-8009
Aug 17, 2015 9:51:22 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 3895 ms

UPDATE #3 更新#3

I'm becoming more convinced there's a configuration problem somewhere. 我越来越相信某处存在配置问题。 On a hunch, I studied and installed Apache TomEE 1.7.2 for Windows , pointing to the same JRE as the regular Tomcat. 实际上 ,我研究并安装了适用于Windows的Apache TomEE 1.7.2 ,指向与常规Tomcat相同的JRE。 After studying the running.txt file and experimenting with the properties and settings, I was finally able launch a local version of TomEE. 在研究了running.txt文件并尝试了属性和设置之后,我终于可以启动本地版本的TomEE了。 I deployed the same WAR file as before, and I found it would not load the WAR application due to the following error: 我像以前一样部署了相同的WAR文件,并且由于以下错误我发现它不会加载WAR应用程序:

java.lang.ClassNotFoundException: com.sun.xml.ws.transport.http.servlet.WSServletContextListener java.lang.ClassNotFoundException:com.sun.xml.ws.transport.http.servlet.WSServletContextListener

Googling that error led (again) to MKYong's blog for a fix (copy the jaxws-rt.jar file to the {$tomcat}/lib folder. I redeployed the WAR file, and the manager loaded the application. HOWEVER, just like on regular Tomcat, the URL " http://localhost:8080/HelloWorld/hello " from the tutorial still returns a 404 error. So, the results are exactly the same. 谷歌搜索该错误(再次)到MKYong的博客进行修复(将jaxws-rt.jar文件复制到{$ tomcat} / lib文件夹。我重新部署了WAR文件,管理器加载了应用程序。但是,就像在常规的Tomcat, 教程中的URL“ http:// localhost:8080 / HelloWorld / hello ”仍然会返回404错误。因此,结果完全相同。

Short of compiling the tutorial against other versions of JDK, I'm running out of ideas quickly... :-) 如果没有针对其他版本的JDK编译教程 ,我的想法很快...... :-)

UPDATE #4 更新#4

Per another request below, here's a list of all JAR files in the {$Tomcat}\\lib folder: 根据下面的另一个请求,这里是{$ Tomcat} \\ lib文件夹中所有JAR文件的列表:

  • annotations-api.jar 注释-api.jar文件
  • catalina.jar catalina.jar
  • catalina-ant.jar 卡塔利娜-的ant.jar
  • catalina-ha.jar 卡特琳娜 - ha.jar
  • catalina-tribes.jar 卡特琳娜 - tribes.jar
  • el-api.jar EL-api.jar文件
  • gmbal-api-only.jar gmbal-API only.jar
  • ha-api.jar HA-api.jar文件
  • jasper.jar jasper.jar
  • jasper-el.jar 碧玉el.jar
  • jasper-jdt.jar 碧玉jdt.jar
  • jaxb-core.jar JAXB-core.jar添加
  • jaxb-impl.jar JAXB - impl.jar中
  • jaxws-api.jar JAXWS-api.jar文件
  • jaxws-rt.jar JAXWS-的rt.jar
  • jsp-api.jar JSP-api.jar文件
  • management-api.jar 管理-api.jar文件
  • policy.jar policy.jar
  • servlet-api.jar servlet的api.jar文件
  • stax-ex.jar STAX-ex.jar
  • streambuffer.jar streambuffer.jar
  • tomcat-coyote.jar Tomcat的coyote.jar
  • tomcat-dbcp.jar Tomcat的dbcp.jar
  • tomcat-i18n-es.jar Tomcat的国际化,es.jar
  • tomcat-i18n-fr.jar Tomcat的国际化,fr.jar
  • tomcat-i18n-ja.jar Tomcat的国际化,ja.jar

The {$Tomcat}\\webapps folder contains the following: {$ Tomcat} \\ webapps文件夹包含以下内容:

  • ..\\com.mkyong.ws .. \\ com.mkyong.ws
  • ..\\docs .. \\文档
  • ..\\examples ..\\例子
  • ..\\host-manager .. \\主机经理
  • ..\\manager ..\\经理
  • ..\\ROOT ..\\根
  • ..\\com.mkyong.ws.war .. \\ com.mkyong.ws.war

Update #5 更新#5

The {$Tomcat}\\webapps\\com.mkyong.ws directory contains the following: {$ Tomcat} \\ webapps \\ com.mkyong.ws目录包含以下内容:

{$ Tomcat} / webapps文件夹中com.mkyong.ws模块目录的屏幕截图

Here's a screenshot of the Tomcat Manager GUI: 以下是Tomcat Manager GUI的屏幕截图:

Tomcat Manager GUI的屏幕截图

Here's a screenshot of the HTTP 404 error I'm receiving along with the URL: 这是我收到的HTTP 404错误的屏幕截图以及URL:

HTTP 404错误的屏幕截图

I've also confirmed that the files in the WAR exactly match the tutorial . 我还确认WAR中的文件与教程完全匹配。

There is problem in deployment of your ws module. 部署ws模块时出现问题。 U have just copied the whole folder from the MKyoung sample. 你刚刚从MKyoung样本中复制了整个文件夹。 I doesn't work that way around. 我不这样做。

Not only that now display all the folders and files structure inside the ws module delete the rest of the modules from your post.I wanted only the structure of ws module. 现在不仅显示ws模块内的所有文件夹和文件结构,还要删除帖子中的其余模块。我只想要ws模块的结构。

The module name has to sample instead of com.mkyoung.ws and the structure for it has to be 模块名称必须采样而不是com.mkyoung.ws,其结构必须是

**sample**
------WEB-INF
------index.jsp

WEB-INF
----classes
----web.xml
----sun-jaxws.xml

classes
----com
--------mkyoung
-----------ws
ws
-----Helloworld.class
-----HeloworldIMPL.class

@NIKETBHANDARY helped me understand what was wrong and how to quickly correct it. @NIKETBHANDARY帮助我了解错误以及如何快速纠正错误。 I'd also like to post exactly what I did wrong and how I fixed it permanently so that future coders can benefit from my five-day experience. 我还想准确发布我做错了什么,以及我如何永久修复它,以便将来的编码员可以从我五天的经验中受益。 :-) :-)

When I originally built the tutorial using Netbeans, I used the Java Web --> Web Application template (which is available after installing the Java EE Base plugin accessible through Netbeans --> Tools --> Plugins ): 当我最初使用Netbeans构建教程时,我使用了Java Web - > Web应用程序模板(在安装可通过Netbeans访问的Java EE Base插件- >工具 - >插件后可用):

Netbeans项目模板

I built all the files exactly per the tutorial , but I failed to really read through step #5, especially this line: 我按照教程完全构建了所有文件,但我没有真正阅读第5步,特别是这一行:

<jar jarfile="${dist}/war/HelloWorld-${DSTAMP}.war" basedir="${dist}/war/build/"/>

After further review, I found that the build script was producing a WAR file called HelloWorld.war . 经过进一步审查后,我发现构建脚本正在生成一个名为HelloWorld.war的WAR文件。 Then, when that file was deployed to Tomcat, the web application was called HelloWorld in the Tomcat Manager. 然后,当该文件部署到Tomcat时,Web应用程序在Tomcat Manager中称为HelloWorld That's why the service endpoint was set to http://localhost:8080/HelloWorld/hello . 这就是服务端点设置为http:// localhost:8080 / HelloWorld / hello的原因 The "HelloWorld" is literally the name of the Tomcat application, and the "/hello" part corresponds with the endpoint from the sun-jaxws.xml file. “HelloWorld”实际上是Tomcat应用程序的名称,“/ hello”部分与sun-jaxws.xml文件中的端点相对应。 (Looking back, it makes total sense given typical web hosting organization. IIS pretty much works the same way.) (回想一下,鉴于典型的网络托管组织,它完全有道理.IIS几乎以同样的方式工作。)

So, to fix the problem, I needed to modify the Netbeans project to produce a WAR file named HelloWorld.war . 因此,为了解决这个问题,我需要修改Netbeans项目以生成一个名为HelloWorld.war的WAR文件。 In the tutorial , he includes an actual Ant build script. 本教程中 ,他包含一个实际的Ant构建脚本。 In this case, I needed to take these steps: 在这种情况下,我需要采取以下步骤:

  1. Right-click on the project in the Netbeans Project Explorer. 在Netbeans Project Explorer中右键单击该项目。
  2. Choose Properties . 选择属性
  3. Click on the Build --> Packaging category. 单击Build - > Packaging类别。
  4. Set the WAR file field to HelloWorld.war . 将WAR文件字段设置为HelloWorld.war

Here is a screenshot: 这是一个截图:

在此输入图像描述

Once that was done, I created a new build, deployed to my local Tomcat server, and everything worked as expected. 完成后,我创建了一个新的构建,部署到我的本地Tomcat服务器,一切都按预期工作。 I was also able to deploy the WAR file to my Linux server and test it successfully. 我还能够将WAR文件部署到我的Linux服务器并成功测试它。 Problem solved! 问题解决了! :-) :-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM