title: Servlet 5.0 JAR throws compile error on javax.servlet.* but Servlet 4.0 JAR does not
body: <p>I am trying to compile and deploy a simple web app from command line.</p>
  <p>servlet-api.jar from Apache Tomcat does not compile my java file, but javax.servlet-api-4.0.1 from the maven central repository compiles it successfully. Even so, I get an error when I deploy the app and try to use it in the browser.</p>
  <p>I am using:</p>
  <ul>
  <li>javac 11.0.8</li>
  <li>Apache Tomcat 10.0 (servlet-api.jar 5.0)</li>
  </ul>
  <p>Java file:</p>
  <pre><code>package com.example.controllers;
  
  import javax.servlet.*;
  import javax.servlet.http.*;
  import java.io.*;
  
  public class BeerSelect extends HttpServlet {
      
      public void doPost(HttpServletRequest request,
              HttpServletResponse response)
              throws IOException, ServletException {
  
          response.setContentType(&quot;text/html&quot;);
          PrintWriter out = response.getWriter();
          out.println(&quot;Beer Selection Advice &lt;br&gt;&quot;);
          String c = request.getParameter(&quot;color&quot;);
          out.println(&quot;&lt;br&gt;Got beer color &quot; + c);
      }               
  } 
  </code></pre>
  <p>When I try to compile it with the servlet-api.jar I get:</p>
  <pre><code>public class BeerSelect extends HttpServlet {
                                  ^
    symbol: class HttpServlet
  src\com\example\controllers\BeerSelect.java:9: error: cannot find symbol
          public void doPost(HttpServletRequest request,
                             ^
    symbol:   class HttpServletRequest
    location: class BeerSelect
  src\com\example\controllers\BeerSelect.java:10: error: cannot find symbol
                          HttpServletResponse response)
                          ^
    symbol:   class HttpServletResponse
    location: class BeerSelect
  src\com\example\controllers\BeerSelect.java:11: error: cannot find symbol
                          throws IOException, ServletException {
                                              ^
    symbol:   class ServletException
    location: class BeerSelect
  src\com\example\controllers\BeerSelect.java:3: error: package javax.servlet does not exist
  import javax.servlet.*;
  ^
  src\com\example\controllers\BeerSelect.java:4: error: package javax.servlet.http does not exist
  import javax.servlet.http.*;
  ^
  6 errors 
  </code></pre>
  <p>However, javax.servlet-api-4.0.1 compiles the file successfully. Note: I've already tested and ruled out command-line command as a possible cause of the problem.</p>
  <p>When I place the .class file in the corresponding Tomcat directory, start the server and try to interact with the app, I get the following exception:</p>
  <pre><code>Exception
  jakarta.servlet.ServletException: Error instantiating servlet class [com.example.controllers.BeerSelect]
  
  Root Cause
  java.lang.NoClassDefFoundError: javax/servlet/http/HttpServlet
  
  Root Cause
  java.lang.ClassNotFoundException: javax.servlet.http.HttpServlet
  
  </code></pre>
  <p>I tried placing the javax.servlet-api-4.0.1 in the Tomcat/lib directory, but then I get:</p>
  <pre><code>Exception
  jakarta.servlet.ServletException: Class [com.example.controllers.BeerSelect] is not a Servlet
  
  Root Cause
  java.lang.ClassCastException: class com.example.controllers.BeerSelect cannot be cast to class jakarta.servlet.Servlet (com.example.controllers.BeerSelect is in unnamed module of loader org.apache.catalina.loader.ParallelWebappClassLoader @7862f56; jakarta.servlet.Servlet is in unnamed module of loader java.net.URLClassLoader @4b4523f8)
  
  </code></pre>
  <p>Not sure the last makes any sense, but I ran out of ideas.</p>
  <p>Any help is more than welcome!</p>