Running a simple java Servlet gives Class is not a Servlet error
<p>I have a simple Java servlet project which I am running via maven tomcat plugin.Hitting the url, I get this error</p>

<pre><code>javax.servlet.ServletException: Class in.vshukla.MyServlet is not a Servlet

java.lang.ClassCastException: in.vshukla.MyServlet cannot be cast to javax.servlet.Servlet
</code></pre>

<p>The servlet class is </p>

<pre><code>import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class MyServlet implements Servlet {
    .
    .
    .
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
        PrintWriter out = servletResponse.getWriter();
        out.println("&lt;html&gt;");
        out.println("&lt;body&gt;");
        out.println("&lt;h1&gt;Hello, world!&lt;/h1&gt;");
        out.println("&lt;/body&gt;");
        out.println("&lt;/html&gt;");
        out.close();
    }
    .
    .
    .
}
</code></pre>

<p>This is accompanied by a simple web.xml file.</p>

<pre><code>&lt;web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
         http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
     version="3.1"&gt;
     &lt;servlet&gt;
         &lt;servlet-name&gt;servlet&lt;/servlet-name&gt;
         &lt;servlet-class&gt;in.vshukla.MyServlet&lt;/servlet-class&gt;
     &lt;/servlet&gt;
     &lt;servlet-mapping&gt;
         &lt;servlet-name&gt;servlet&lt;/servlet-name&gt;
         &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
     &lt;/servlet-mapping&gt;
&lt;/web-app&gt;
</code></pre>

<p>I have cross checked the war file generated. I am attaching the output of tree command on the war file.</p>

<pre>
.
|-- META-INF
`-- WEB-INF
    |-- classes
    |   |-- in
    |   |   `-- vshukla
    |   |       `-- MyServlet.class
    |   `-- spring
    |       `-- spring_config.xml
    |-- lib
    |   |-- javax.servlet-api-3.1.0.jar
    |   `-- my-data-0.1-SNAPSHOT.jar
    `-- web.xml

7 directories, 5 files
</pre>

<p>I am building this using maven.
The following is the pom.xml file.</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
&lt;project xmlns="http://maven.apache.org/POM/4.0.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;

  &lt;parent&gt;
    &lt;groupId&gt;in.vshukla&lt;/groupId&gt;
    &lt;artifactId&gt;my&lt;/artifactId&gt;
    &lt;version&gt;0.1-SNAPSHOT&lt;/version&gt;
  &lt;/parent&gt;
  &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  &lt;artifactId&gt;my-api&lt;/artifactId&gt;
  &lt;packaging&gt;war&lt;/packaging&gt;

  &lt;properties&gt;
    &lt;javax.version&gt;3.1.0&lt;/javax.version&gt;
  &lt;/properties&gt;
  &lt;dependencies&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;in.vshukla&lt;/groupId&gt;
      &lt;artifactId&gt;my-data&lt;/artifactId&gt;
      &lt;version&gt;${project.parent.version}&lt;/version&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
      &lt;artifactId&gt;javax.servlet-api&lt;/artifactId&gt;
      &lt;version&gt;${javax.version}&lt;/version&gt;
    &lt;/dependency&gt;
  &lt;/dependencies&gt;

&lt;/project&gt;
</code></pre>

<p>Even though the class MyServlet is implementing a javax Servlet, I am getting this error.</p>

<p>What am I doing wrong?</p>