title: Why Tomcat server is not working with the web.xml file as servlet configuration used in a Vaadin 7 application?
body: <p>I can't start Tomcat when I use web.xml as the configuration file for the servlets in an application, this is the content of the file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app
    id="WebApp_ID" version="3.0"
    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/javaee
       http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"&gt;
  
    &lt;servlet&gt;
      &lt;servlet-name&gt;AppLifeServlet&lt;/servlet-name&gt;
      &lt;servlet-class&gt;
          com.example.application_lifecycle_chapter_4_7.ApplicatationLifecycleUI.Servlet
      &lt;/servlet-class&gt;
      &lt;init-param&gt;
        &lt;param-name&gt;UI&lt;/param-name&gt;
        &lt;param-value&gt;com.example.application_lifecycle_chapter_4_7.ApplicationLifecycleUI&lt;/param-value&gt;
      &lt;/init-param&gt;
      &lt;async-supported&gt;true&lt;/async-supported&gt;
    &lt;/servlet&gt;
  
    &lt;servlet&gt;
        &lt;servlet-name&gt;MyPushyServlet&lt;/servlet-name&gt;
        &lt;servlet-class&gt;
            com.example.application_lifecycle_chapter_4_7.MyPushyUI.Servlet
        &lt;/servlet-class&gt;
        &lt;init-param&gt;
          &lt;param-name&gt;UI&lt;/param-name&gt;
          &lt;param-value&gt;com.example.application_lifecycle_chapter_4_7.MyPushyUI&lt;/param-value&gt;
        &lt;/init-param&gt;
        &lt;async-supported&gt;true&lt;/async-supported&gt;
    &lt;/servlet&gt;    
  
    &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;AppLifeServlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/AppLife/*&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  
    &lt;servlet-mapping&gt;
        &lt;servlet-name&gt;AppLifeServlet&lt;/servlet-name&gt;
        &lt;url-pattern&gt;/VAADIN/*&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  
    &lt;servlet-mapping&gt;
        &lt;servlet-name&gt;MyPushyServlet&lt;/servlet-name&gt;
        &lt;url-pattern&gt;/MyPushyUI/*&lt;/url-pattern&gt;
    &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>Why is it not working? Tomcat even doesn't start and instead returns an exception:</p>
  
  <pre><code>SEVERE: Failed to destroy end point associated with ProtocolHandler ["ajp-nio-8009"]
  java.lang.NullPointerException
      at org.apache.tomcat.util.net.NioEndpoint.releaseCaches(NioEndpoint.java:307)
      at org.apache.tomcat.util.net.NioEndpoint.unbind(NioEndpoint.java:482)
      at org.apache.tomcat.util.net.AbstractEndpoint.destroy(AbstractEndpoint.java:795)
      at org.apache.coyote.AbstractProtocol.destroy(AbstractProtocol.java:531)
      at org.apache.catalina.connector.Connector.destroyInternal(Connector.java:1023)
      at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:305)
      at org.apache.catalina.core.StandardService.destroyInternal(StandardService.java:588)
      at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:305)
      at org.apache.catalina.core.StandardServer.destroyInternal(StandardServer.java:850)
      at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:305)
      at org.apache.catalina.startup.Catalina.start(Catalina.java:629)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:483)
      at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:351)
      at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:485)
  </code></pre>
  
  <p>If I disable web.xml and I use Servlet's 3.0 API annotations everything works... </p>
  
  <p>What's the problem with the web.xml file?</p>
  
  <p>EDIT: Here is the full exception output when Tomcat tries to start:</p>
  
  <pre><code>SEVERE: A child container failed during start
  java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/Application_Lifecycle_Chapter_4.7]]
      at java.util.concurrent.FutureTask.report(FutureTask.java:122)
      at java.util.concurrent.FutureTask.get(FutureTask.java:192)
      at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:917)
      at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:868)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1399)
      at java.util.concurrent.FutureTask.run(FutureTask.java:266)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      at java.lang.Thread.run(Thread.java:745)
  Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/Application_Lifecycle_Chapter_4.7]]
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
      ... 6 more
  Caused by: java.lang.IllegalArgumentException: The servlets named [AppLifeServlet] and [com.example.application_lifecycle_chapter_4_7.ApplicationLifecycleUI$Servlet] are both mapped to the url-pattern [/AppLife/*] which is not permitted
      at org.apache.tomcat.util.descriptor.web.WebXml.addServletMapping(WebXml.java:308)
      at org.apache.catalina.startup.ContextConfig.processAnnotationWebServlet(ContextConfig.java:2325)
      at org.apache.catalina.startup.ContextConfig.processAnnotationsStream(ContextConfig.java:2007)
      at org.apache.catalina.startup.ContextConfig.processAnnotationsWebResource(ContextConfig.java:1901)
      at org.apache.catalina.startup.ContextConfig.processAnnotationsWebResource(ContextConfig.java:1896)
      at org.apache.catalina.startup.ContextConfig.processAnnotationsWebResource(ContextConfig.java:1896)
      at org.apache.catalina.startup.ContextConfig.processAnnotationsWebResource(ContextConfig.java:1896)
      at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1139)
      at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:771)
      at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:305)
      at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
      at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
      at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5095)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
      ... 6 more
  
  Dec 07, 2014 7:49:30 PM org.apache.catalina.core.ContainerBase startInternal
  SEVERE: A child container failed during start
  java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]]
      at java.util.concurrent.FutureTask.report(FutureTask.java:122)
      at java.util.concurrent.FutureTask.get(FutureTask.java:192)
      at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:917)
      at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
      at org.apache.catalina.core.StandardService.startInternal(StandardService.java:439)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
      at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:760)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
      at org.apache.catalina.startup.Catalina.start(Catalina.java:625)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:483)
      at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:351)
      at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:485)
  Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost]]
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409)
      at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1399)
      at java.util.concurrent.FutureTask.run(FutureTask.java:266)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      at java.lang.Thread.run(Thread.java:745)
  Caused by: org.apache.catalina.LifecycleException: A child container failed during start
      at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:925)
      at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:868)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
      ... 6 more
  
  Dec 07, 2014 7:49:30 PM org.apache.catalina.startup.Catalina start
  SEVERE: The required Server component failed to start so Tomcat is unable to start.
  org.apache.catalina.LifecycleException: Failed to start component [StandardServer[8005]]
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
      at org.apache.catalina.startup.Catalina.start(Catalina.java:625)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:483)
      at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:351)
      at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:485)
  Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardService[Catalina]]
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
      at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:760)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
      ... 7 more
  Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina]]
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)
      at org.apache.catalina.core.StandardService.startInternal(StandardService.java:439)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
      ... 9 more
  Caused by: org.apache.catalina.LifecycleException: A child container failed during start
      at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:925)
      at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
      at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
      ... 11 more
  
  Dec 07, 2014 7:49:30 PM org.apache.coyote.AbstractProtocol pause
  INFO: Pausing ProtocolHandler ["http-nio-8080"]
  Dec 07, 2014 7:49:30 PM org.apache.coyote.AbstractProtocol pause
  INFO: Pausing ProtocolHandler ["ajp-nio-8009"]
  Dec 07, 2014 7:49:30 PM org.apache.catalina.core.StandardService stopInternal
  INFO: Stopping service Catalina
  Dec 07, 2014 7:49:30 PM org.apache.coyote.AbstractProtocol destroy
  INFO: Destroying ProtocolHandler ["http-nio-8080"]
  Dec 07, 2014 7:49:30 PM org.apache.coyote.AbstractProtocol destroy
  SEVERE: Failed to destroy end point associated with ProtocolHandler ["http-nio-8080"]
  java.lang.NullPointerException
      at org.apache.tomcat.util.net.NioEndpoint.releaseCaches(NioEndpoint.java:307)
      at org.apache.tomcat.util.net.NioEndpoint.unbind(NioEndpoint.java:482)
      at org.apache.tomcat.util.net.AbstractEndpoint.destroy(AbstractEndpoint.java:795)
      at org.apache.coyote.AbstractProtocol.destroy(AbstractProtocol.java:531)
      at org.apache.catalina.connector.Connector.destroyInternal(Connector.java:1023)
      at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:305)
      at org.apache.catalina.core.StandardService.destroyInternal(StandardService.java:588)
      at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:305)
      at org.apache.catalina.core.StandardServer.destroyInternal(StandardServer.java:850)
      at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:305)
      at org.apache.catalina.startup.Catalina.start(Catalina.java:629)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:483)
      at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:351)
      at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:485)
  
  Dec 07, 2014 7:49:30 PM org.apache.coyote.AbstractProtocol destroy
  INFO: Destroying ProtocolHandler ["ajp-nio-8009"]
  Dec 07, 2014 7:49:30 PM org.apache.coyote.AbstractProtocol destroy
  SEVERE: Failed to destroy end point associated with ProtocolHandler ["ajp-nio-8009"]
  java.lang.NullPointerException
      at org.apache.tomcat.util.net.NioEndpoint.releaseCaches(NioEndpoint.java:307)
      at org.apache.tomcat.util.net.NioEndpoint.unbind(NioEndpoint.java:482)
      at org.apache.tomcat.util.net.AbstractEndpoint.destroy(AbstractEndpoint.java:795)
      at org.apache.coyote.AbstractProtocol.destroy(AbstractProtocol.java:531)
      at org.apache.catalina.connector.Connector.destroyInternal(Connector.java:1023)
      at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:305)
      at org.apache.catalina.core.StandardService.destroyInternal(StandardService.java:588)
      at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:305)
      at org.apache.catalina.core.StandardServer.destroyInternal(StandardServer.java:850)
      at org.apache.catalina.util.LifecycleBase.destroy(LifecycleBase.java:305)
      at org.apache.catalina.startup.Catalina.start(Catalina.java:629)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:483)
      at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:351)
      at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:485)
  </code></pre>
  
  <p>RESOLVED: This is the crucial line:</p>
  
  <pre><code> Caused by: java.lang.IllegalArgumentException: The servlets named [AppLifeServlet] and 
      [com.example.application_lifecycle_chapter_4_7.ApplicationLifecycleUI$Servlet] are both 
      mapped to the url-pattern [/AppLife/*] which is not permitted
  </code></pre>
  
  <p>From the Book of Vaadin:</p>
  
  <blockquote>
    <p>You can use both a web.xml and WebServlet in the same application.
    Settings in the web.xml override the ones given in annotations.</p>
  </blockquote>
  
  <p><strong>This is not true</strong>! In my case the error was due this phrase: I had a <code>@WebServlet</code> annotation in my <code>ApplicationLifecycleUI$Servlet</code> together with the servlet mapping inside the web.xml file.</p>
  
  <p>The two configurations can't coexist together, so you must choose whether to use web.xml or <code>@WebServlet</code> annotation for the URL mapping, or you will get this error when you are trying to start Tomcat.</p>