小编典典

Tomcat无法部署.war

tomcat

我正在尝试按照教程创建简单的REST Web服务,但是我将其部署在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]]

我看了看周围的解决方案,发现这个问题他们让我觉得这是一个servlet的映射问题但是我不知道如何解决它!

这是我的日志文件:

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>

冒着给您太多信息的危险,这是我的文件夹结构的ls:

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

阅读 265

收藏
2020-06-16

共1个答案

小编典典

如上面的注释所示,问题出在应用程序web.xml引用了servlet定义中的java类。通过确保应用程序实际包含该类来解决此问题。找到缺少的jar文件,并将其放在WEB-INF / lib目录中。

2020-06-16