title: Severe error in re-deploying servlet - silly error
body: <p>I was trying to redeploy a servlet I had recently undeployed but kept getting a <code>org.apache.catalina.LifecycleException</code>. Tomcat wasn't able to load the context properly.</p>
  
  <p>This is what triggered the search:</p>
  
  <pre><code>FAIL - Unable to delete [/var/lib/tomcat7/conf/Catalina/localhost/app.xml].
         The continued presence of this file may cause problems.
  </code></pre>
  
  <p>Here are the errors from the log <code>catalina.out</code>, rearranged to fit the column:</p>
  
  <pre><code>WARNING: Calling stop() on failed component [{0}] to trigger clean-up
           did not complete.
  org.apache.catalina.LifecycleException: 
           An invalid Lifecycle transition was attempted ([after_stop]) for 
           component [org.apache.catalina.startup.FailedContext@13150fc] in state
           [FAILED]
  
  WARNING: Error while removing context [/app]
  java.lang.ClassCastException:
           org.apache.catalina.startup.FailedContext cannot be cast to 
           org.apache.catalina.core.StandardContext
  </code></pre>
  
  <p>Scrolling back up, I noticed a whole list of <code>SEVERE</code> errors, beginning with:</p>
  
  <pre><code>SEVERE: Parse error in context.xml for /app
      org.xml.sax.SAXParseException; 
      systemId: file:/etc/tomcat7/Catalina/localhost/app.xml/;
      lineNumber: 1;
      columnNumber: 1;
      Content is not allowed in prolog.
  </code></pre>
  
  <p>This is not related to <a href="https://stackoverflow.com/questions/14873219/">Cannot Undeploy a web-app completely in Tomcat 7</a> or <a href="https://stackoverflow.com/questions/15613918/">Installing JSTL results in org.xml.sax.SAXParseException: Content is not allowed in prolog</a>, though I wasted quite some time looking through these. Everything seemed to be as it should be, so I was stumped. Eventually, I solved it myself. My answer is below.</p>