title: Tomcat is unable to find my Servlet and is throwing exceptions, but why?
body: <p>I'm trying to get into Java web development but seem to be running into a strange issue with Tomcat and an extremely simple servlet. The catalina log is spewing this every time I try and load the app:</p>
  
  <pre><code>Caused by: java.lang.IllegalArgumentException: Servlet mapping specifies an unknown servlet name MyServlet
      at org.apache.catalina.core.StandardContext.addServletMapping(StandardContext.java:2393)
      at org.apache.catalina.core.StandardContext.addServletMapping(StandardContext.java:2373)
      ... 40 more
  Mar 4, 2009 10:37:58 AM org.apache.catalina.startup.ContextConfig applicationWebConfig
  SEVERE: Parse error in application web.xml file at jndi:/localhost/mywebapp/WEB-INF/web.xml
  java.lang.IllegalArgumentException: Servlet mapping specifies an unknown servlet name MyServlet
  </code></pre>
  
  <p>Makes decent sense. It can't seem to find my servlet. However, the servlet seems to be in the right place. I can plainly see it at <strong>WEB-INF/classes/MyServlet.class</strong></p>
  
  <p>For reference, this is the web.xml file I'm currently using:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;
  &lt;web-app xmlns="http://java.sun.com/xml/ns/javaee" 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_2_5.xsd" version="2.5"&gt; 
      &lt;description&gt;My first web app in Java.&lt;/description&gt;
      &lt;display-name&gt;My Web App&lt;/display-name&gt;
  
      &lt;servlet&gt;
          &lt;servlet-name&gt;MyServlet&lt;/servlet-name&gt;
          &lt;servlet-class&gt;MyServlet&lt;/servlet-class&gt;
      &lt;/servlet&gt;
  
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;MyServlet&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/myservlet&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>As you can see, I'm keeping things simple... but it continually throws this exception. What does a bare-bones web app look like in Java, which components am I missing?</p>
  
  <p><strong>Update</strong></p>
  
  <p>To make absolutely certain it wasn't an artifact of some kind, I started up a fresh copy of Tomcat and tried again. Upon doing so, this started appearing in the log files:</p>
  
  <pre><code>SEVERE: Error deploying web application archive mywebapp.war
  java.lang.UnsupportedClassVersionError: Bad version number in .class file (unable to load class MyServlet)
  </code></pre>
  
  <p>I dumped my .class file for the MyServlet class, rebuilt it with -target 1.5, repackaged the .war and everything worked perfectly.</p>
  
  <p>Thank you so much for the help! A good lesson in troubleshooting never hurt anybody.</p>