无法在Apache Tomcat上运行JAX-WS Java Web Service [英] Cannot run JAX-WS Java Web Service on Apache Tomcat

查看:103
本文介绍了无法在Apache Tomcat上运行JAX-WS Java Web Service的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

摘要



我的任务是编写一个Java Web服务,在我们的企业环境中集成两个不同的系统。由于我实际上是一位经验丰富的C#.NET MVC开发人员,并且只考虑自己是Java的中间人,所以我开始搜索Java Web Service Tutorials。我正在尝试运行



以下是Tomcat Manager GUI的屏幕截图:





以下是我收到的HTTP 404错误的屏幕截图以及网址:





我还确认WAR中的文件与教程

解决方案

部署ws模块时出现问题。
你刚刚从MKyoung样本中复制了整个文件夹。
我不会这样做。



现在不仅显示ws模块内的所有文件夹和文件结构,还要删除其余的模块你的帖子。我只想要ws模块的结构。



模块名称必须是样本而不是com.mkyoung.ws
,它的结构有要

  **样本** 
------ WEB-INF
- ---- index.jsp

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


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


Summary

I've been tasked to write a Java web service to integrate two disparate systems in our enterprise environment. 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". I am trying to run this common tutorial, but I'm unable to run the tutorial service due to an HTTP 404 error.

Process

I'm using the Java Web Application template in Netbeans 8.0.2. 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). Everything compiles to a WAR file just fine.

I then deployed the WAR file by loading the server's Tomcat Manager GUI and using the WAR file to deploy feature. When I do so, the WAR file is copied, and the application starts. 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.

Server Environment

  • Oracle Enterprise Linux distro, version 3.8.13-44.1.1.el6uek.x86_64
  • Apache Tomcat 6.0.24
  • 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. However, I may not be able to change all the factors due to limitations with my Linux distro (per my server admin).

Things I've tried (in order):

Setup a Local Tomcat Server on Windows

I installed a local Tomcat Server on my Windows 7 laptop. 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. 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).

Just as on the Linux server, my local Tomcat server couldn't start the tutorial. Manually clicking the start command link gives me the message "FAIL - Application at context path /com.mkyong.ws could not be started". 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

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

For reference, here's a list of the files I've copied:

  • gmbal-api-only.jar
  • ha-api.jar
  • jaxb-core.jar
  • jaxb-impl.jar
  • jaxws-api.jar
  • jaxws-rt.jar
  • management-api.jar
  • policy.jar
  • stax-ex.jar
  • streambuffer.jar

Enabling DEBUG mode in the local Tomcat Server

I un-deployed the WAR file. Using the Apache Tomcat Monitor, I stopped the service, deleted the existing logs, enabled the DEBUG logging level, and restarted the service. I then re-deployed the tutorial WAR file. 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.

Running the service using the Netbeans-embedded Glassfish server

When I first created the Web Application, Netbeans offered to set me up with a local Glassfish server. 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.

Researching other posts and tutorials

Here are some other StackOverflow posts and websites I've reviewed without finding a resolution:

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? (He doesn't give an versions of Java or Tomcat.)
  • Should I run local Tomcat against a JDK instead of a JRE?
  • Should the tutorial be compiled against the same JDK as Tomcat is using? (I hope not as this would seem very limiting...)
  • Can I even run JAX-WS in Tomcat? (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.)

I'd appreciate any troubleshooting guidance anyone can offer. Thank you in advance for the help!

UPDATE #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. I then opened the catalina.log file, but it's completely empty. Only jakarta_service.log has any log entries, and all are about the service starting. I also verified that the logging level is set to debug. What else can I change to get additional log messages?

I also ran a search for "com.mkyong" in the entire Tomcat directory. 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. Nothing in any logs. Could that indicate that this is a configuration problem?

UPDATE #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). 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):

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

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. After studying the running.txt file and experimenting with the properties and settings, I was finally able launch a local version of TomEE. I deployed the same WAR file as before, and I found it would not load the WAR application due to the following error:

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.

Short of compiling the tutorial against other versions of JDK, I'm running out of ideas quickly... :-)

UPDATE #4

Per another request below, here's a list of all JAR files in the {$Tomcat}\lib folder:

  • annotations-api.jar
  • catalina.jar
  • catalina-ant.jar
  • catalina-ha.jar
  • catalina-tribes.jar
  • el-api.jar
  • gmbal-api-only.jar
  • ha-api.jar
  • jasper.jar
  • jasper-el.jar
  • jasper-jdt.jar
  • jaxb-core.jar
  • jaxb-impl.jar
  • jaxws-api.jar
  • jaxws-rt.jar
  • jsp-api.jar
  • management-api.jar
  • policy.jar
  • servlet-api.jar
  • stax-ex.jar
  • streambuffer.jar
  • tomcat-coyote.jar
  • tomcat-dbcp.jar
  • tomcat-i18n-es.jar
  • tomcat-i18n-fr.jar
  • tomcat-i18n-ja.jar

The {$Tomcat}\webapps folder contains the following:

  • ..\com.mkyong.ws
  • ..\docs
  • ..\examples
  • ..\host-manager
  • ..\manager
  • ..\ROOT
  • ..\com.mkyong.ws.war

Update #5

The {$Tomcat}\webapps\com.mkyong.ws directory contains the following:

Here's a screenshot of the Tomcat Manager GUI:

Here's a screenshot of the HTTP 404 error I'm receiving along with the URL:

I've also confirmed that the files in the WAR exactly match the tutorial.

解决方案

There is problem in deployment of your ws module. U have just copied the whole folder from the MKyoung sample. 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.

The module name has to sample instead of com.mkyoung.ws and the structure for it has to be

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

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

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

这篇关于无法在Apache Tomcat上运行JAX-WS Java Web Service的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆