Jax-ws战争部署,但在tomcat上提供404

时间:2016-06-23 21:43:02

标签: tomcat jax-ws

首先我看了一下建议的类似问题 - 因为这显然是一个相当普遍的问题 - 而且还没有找到答案。我哪里出错了?下载最新的JAXWS-RI并手动复制所有.jar文件。然后拼凑一个web.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems,Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
    <listener>
        <listener-class>
           com.sun.xml.ws.transport.http.servlet.WSServletContextListener
        </listener-class>
    </listener>
    <servlet>
        <servlet-name>HelloWorldTomcatService</servlet-name>
        <servlet-class>
            com.sun.xml.ws.transport.http.servlet.WSServlet
        </servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>HelloWorldTomcatService</servlet-name>
        <url-pattern>/HelloWorldTomcatService</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>30</session-timeout>
    </session-config>
    </web-app>

和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">
    <endpoint name="HelloWorldTomcatService" implementation="com.myservice.ws.Hello" url-pattern="/HelloWorldTomcatService"/>
</endpoints>

和几个java文件

package com.myservice.ws;
import javax.jws.WebMethod;
import javax.jws.WebService;
@WebService
public interface WebServiceInterface {
    @WebMethod
    String printMessage();
}

package com.myservice.ws;
import javax.jws.WebService;

@WebService(endpointInterface = "com.myservice.ws.WebServiceInterface")
public class Hello implements WebServiceInterface{
    @Override
    public String printMessage() {
        return "message";
    }
}

我将四个文件放在适当的目录结构中,并在eclipse中构建war文件并将其复制到Tomcat webapps文件夹中。战争爆炸并显示在管理器控制台上,但它没有启动,所有在浏览器中访问它的尝试都失败了。

更新

这是catalina日志以外的其他内容。

24-Jun-2016 11:22:42.164 INFO [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.startup.HostConfig.undeploy Undeploying context [/HelloWorldTomcatService]
24-Jun-2016 11:22:42.171 INFO [localhost-startStop-6] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.5\webapps\HelloWorldTomcatService.war
24-Jun-2016 11:22:42.261 SEVERE [localhost-startStop-6] org.apache.catalina.startup.ContextConfig.configureStart Marking this application unavailable due to previous error(s)
24-Jun-2016 11:22:42.262 SEVERE [localhost-startStop-6] org.apache.catalina.core.StandardContext.startInternal One or more components marked the context as not correctly configured
24-Jun-2016 11:22:42.262 SEVERE [localhost-startStop-6] org.apache.catalina.core.StandardContext.startInternal Context [/HelloWorldTomcatService] startup failed due to previous errors
24-Jun-2016 11:22:42.265 INFO [localhost-startStop-6] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.5\webapps\HelloWorldTomcatService.war has finished in 94 ms
24-Jun-2016 12:53:45.577 INFO [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.startup.HostConfig.undeploy Undeploying context [/HelloWorldTomcatService]
24-Jun-2016 12:53:45.596 INFO [localhost-startStop-7] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.5\webapps\HelloWorldTomcatService.war
24-Jun-2016 12:53:45.665 SEVERE [localhost-startStop-7] org.apache.catalina.startup.ContextConfig.configureStart Marking this application unavailable due to previous error(s)

更多日志:

22-Jun-2016 17:32:47.921 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.5\webapps\HelloWorldTomcatService.war
22-Jun-2016 17:32:48.036 SEVERE [localhost-startStop-1] org.apache.tomcat.util.descriptor.web.WebXmlParser.parseWebXml Parse error in application web.xml file at file:/C:/Program%20Files%20(x86)/Apache%20Software%20Foundation/Tomcat%208.5/webapps/HelloWorldTomcatService/WEB-INF/web.xml
 java.io.FileNotFoundException: Could not resolve XML resource [null] with public ID [-//Sun Microsystems,Inc.//DTD Web Application 2.3//EN], system ID [http://java.sun.com/j2ee/dtds/web-app_2_3.dtd] and base URI [file:/C:/Program%20Files%20(x86)/Apache%20Software%20Foundation/Tomcat%208.5/webapps/HelloWorldTomcatService/WEB-INF/web.xml] to a known, local entity.
    at org.apache.tomcat.util.descriptor.LocalResolver.resolveEntity(LocalResolver.java:155)
    at com.sun.org.apache.xerces.internal.util.EntityResolver2Wrapper.resolveEntity(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLEntityManager.resolveEntityAsPerStax(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.dispatch(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver.next(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
    at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1461)
    at org.apache.tomcat.util.descriptor.web.WebXmlParser.parseWebXml(WebXmlParser.java:120)
    at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1110)
    at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:771)
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:298)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:94)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5076)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:152)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:726)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:702)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:952)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1823)
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

22-Jun-2016 17:32:48.051 WARNING [localhost-startStop-1] org.apache.tomcat.util.scan.StandardJarScanner.scan Failed to scan [file:/C:/Program%20Files%20(x86)/Apache%20Software%20Foundation/Tomcat%208.5/lib/hk2-core.jar] from classloader hierarchy
 java.io.FileNotFoundException: C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.5\lib\hk2-core.jar (The system cannot find the file specified)
    at java.util.zip.ZipFile.open(Native Method)
    at java.util.zip.ZipFile.<init>(Unknown Source)
    at java.util.zip.ZipFile.<init>(Unknown Source)
    at java.util.jar.JarFile.<init>(Unknown Source)
    at java.util.jar.JarFile.<init>(Unknown Source)
    at org.apache.tomcat.util.scan.JarFileUrlJar.<init>(JarFileUrlJar.java:60)
    at org.apache.tomcat.util.scan.JarFactory.newInstance(JarFactory.java:43)
    at org.apache.tomcat.util.scan.StandardJarScanner.process(StandardJarScanner.java:326)
    at org.apache.tomcat.util.scan.StandardJarScanner.scan(StandardJarScanner.java:276)
    at org.apache.catalina.startup.ContextConfig.processJarsForWebFragments(ContextConfig.java:1887)
    at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1122)
    at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:771)
    at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:298)
    at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:94)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5076)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:152)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:726)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:702)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:952)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1823)
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

1 个答案:

答案 0 :(得分:2)

以防万一有人好奇:我遇到的问题是web.xml的标题与我使用的Tomcat版本不兼容 - 或者已弃用,我不知道。

现在正在使用的标题是:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
      http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
      version="2.4">
...

还有警告说hk2-core.jar丢失了。如果我先修复xml问题,我不确定会出现问题,但这是一个很好的问题,所以,支持Kolossus。