Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tomcat failing to deploy .war

Tags:

I'm trying to follow this tutorial on creating a simple REST web service, however I get to deploying it on tomcat and it throws an exception:

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

I've looked around for a solution and found this question and this one and they make me think that it's a servlet-mapping problem however I'm not sure how to fix it!

Here is my log file:

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)

here is my web.xml file:

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

and at the risk of giving you all far too much information, here is a ls of my folder structure:

.:
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
like image 687
Pete Avatar asked Dec 17 '12 23:12

Pete


People also ask

How do I deploy a WAR file in Tomcat?

9.2. WAR File to Deploy Just click the choose file button, navigate to the location of the WAR file and select it, then click the deploy button. In both situations, if all goes well, the Tomcat console will inform us that the deployment has been successful with a message like the following:

Why doesn't my Tomcat application deploy automatically?

This is handled automatically by Tomcat 's autoDeploy feature. If your application does not deploy automatically, there is either a problem in the web.xml file, the web.xml file is in the wrong location, or autoDeploy is disabled. Make sure the web.xml file is called web.xml (in lower case), and contains a valid deployment descriptor.

Where are Tomcat project files stored after deployment?

After deploying our WAR file, Tomcat unpacks it and stores all project files in the webapps directory in a new directory named after the project. 3.

What do I do if Tomcat manager is not available?

If no Tomcat Manager is available, check the logs to see the deployment errors, and then check the error message list below. If this message appears, the /myNewApp application has already been deployed.


1 Answers

As the above comment shows, the problem turned out to be that the application web.xml referenced a java class in a servlet definition. The problem was corrected by making sure the application actually contained that class. The missing jar file was located and put in the WEB-INF/lib directory.

like image 196
EJK Avatar answered Sep 22 '22 08:09

EJK