Tomcat未能部署.war

时间:2012-12-17 23:06:23

标签: java rest tomcat war illegalstateexception

我正在尝试关注创建一个简单的REST Web服务的this教程,但是我可以在tomcat上部署它并抛出异常:

FAIL - Application at context path /restful could not be started
FAIL - Encountered exception org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/restful]]

我已经四处寻找解决方案并找到了这个question和这个one,他们让我觉得这是一个servlet映射问题,但我不知道如何解决它!< / p>

这是我的日志文件:

18/12/2012 9:57:16 AM org.apache.catalina.startup.HostConfig deployWAR
SEVERE: Error deploying web application archive /opt/tomcat7/webapps/restful.war
java.lang.IllegalStateException: ContainerBase.addChild: start:
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/restful]]
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:904)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:977)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1655)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:619)

这是我的web.xml文件:

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

  <servlet>
    <servlet-name>RestfulContainer</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
    <init-param>
        <param-name>com.sun.jersey.config.property.packages</param-name>
        <param-value>com.mcnz.ws</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>RestfulContainer</servlet-name>
    <url-pattern>/resources/*</url-pattern>
  </servlet-mapping>    

</web-app>

并且冒着给你所有太多信息的风险,这里有我的文件夹结构:

.:
WEB-INF

./WEB-INF:
classes
lib
web.xml

./WEB-INF/classes:
com

./WEB-INF/classes/com:
mcnz

./WEB-INF/classes/com/mcnz:
ws

./WEB-INF/classes/com/mcnz/ws:
HelloWorldResource.class
HelloWorldResource.java

./WEB-INF/lib:
asm-3.1.jar
jackson-core-asl-1.9.2.jar
jackson-jaxrs-1.9.2.jar
jackson-mapper-asl-1.9.2.jar
jackson-xc-1.9.2.jar
jersey-client-1.16.jar
jersey-core-1.16.jar
jersey-json-1.16.jar
jersey-server-1.16.jar
jettison-1.1.jar
jsr311-api-1.1.1.jar

2 个答案:

答案 0 :(得分:11)

正如上面的评论所示,问题结果是应用程序web.xml引用了servlet定义中的java类。通过确保应用程序实际包含该类来纠正问题。找到丢失的jar文件并将其放在WEB-INF / lib目录中。

答案 1 :(得分:0)

让ncwms在Apache Tomcat / 8.5.38上运行时遇到了类似的问题 显然,我现在需要添加一些额外的Java库,这些库已在最新的Java版本中删除。

(在此处查看详细信息:How to resolve java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException in Java 9

更改在此文件中: /opt/tomcat/bin/catalina.sh

JAVA_OPTS="$JAVA_OPTS $JSSE_OPTS --add-modules java.xml.bind"

但是对于ncwms来说,这还远远不够。后来在导入数据集时遇到了问题,因此我恢复为其他版本的Java:

java -version
openjdk version "1.8.0_191"
OpenJDK Runtime Environment (build 1.8.0_191-8u191-b12-2ubuntu0.18.04.1-b12)
OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)