title: How to use gradle to create a MANIFEST.MF file for a servlet?
body: <p>How do I use <code>gradle</code> to <a href="https://stackoverflow.com/q/574594/4531180">create a</a> deployable <code>WAR</code> file with, in particular, a correct <code>MANIFEST.MF</code> file?</p>
  <p>the resulting <code>WAR</code> file:</p>
  <pre><code>[nsaunders@rolly libs]$ 
  [nsaunders@rolly libs]$ ls
  hello_jsp.war
  [nsaunders@rolly libs]$ 
  [nsaunders@rolly libs]$ jar xf hello_jsp.war 
  [nsaunders@rolly libs]$ 
  [nsaunders@rolly libs]$ tree
  .
  ├── hello_jsp.war
  ├── META-INF
  │   └── MANIFEST.MF
  └── WEB-INF
      ├── classes
      │   └── servlets
      │       └── NewServlet.class
      └── lib
          ├── checker-qual-2.11.1.jar
          ├── commons-math3-3.6.1.jar
          ├── error_prone_annotations-2.3.4.jar
          ├── failureaccess-1.0.1.jar
          ├── guava-29.0-jre.jar
          ├── j2objc-annotations-1.3.jar
          ├── jsr305-3.0.2.jar
          └── listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar
  
  5 directories, 11 files
  [nsaunders@rolly libs]$ 
  [nsaunders@rolly libs]$ cat META-INF/MANIFEST.MF 
  Manifest-Version: 1.0
  
  [nsaunders@rolly libs]$ 
  </code></pre>
  <p>However, as above, the <code>MANIFEST.MF</code> is actually blank.</p>
  <p>sample servlet:</p>
  <pre><code>package servlets;
  
  import java.io.IOException;
  import java.io.PrintWriter;
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServlet;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  
  public class NewServlet extends HttpServlet {
  
      /**
       * Processes requests for both HTTP &lt;code&gt;GET&lt;/code&gt; and &lt;code&gt;POST&lt;/code&gt;
       * methods.
       *
       * @param request servlet request
       * @param response servlet response
       * @throws ServletException if a servlet-specific error occurs
       * @throws IOException if an I/O error occurs
       */
      protected void processRequest(HttpServletRequest request, HttpServletResponse response)
              throws ServletException, IOException {
          response.setContentType(&quot;text/html;charset=UTF-8&quot;);
          try (PrintWriter out = response.getWriter()) {
              /* TODO output your page here. You may use following sample code. */
              out.println(&quot;&lt;!DOCTYPE html&gt;&quot;);
              out.println(&quot;&lt;html&gt;&quot;);
              out.println(&quot;&lt;head&gt;&quot;);
              out.println(&quot;&lt;title&gt;Servlet NewServlet&lt;/title&gt;&quot;);            
              out.println(&quot;&lt;/head&gt;&quot;);
              out.println(&quot;&lt;body&gt;&quot;);
              out.println(&quot;&lt;h1&gt;Servlet NewServlet at &quot; + request.getContextPath() + &quot;&lt;/h1&gt;&quot;);
              out.println(&quot;&lt;/body&gt;&quot;);
              out.println(&quot;&lt;/html&gt;&quot;);
          }
      }
  
      // &lt;editor-fold defaultstate=&quot;collapsed&quot; desc=&quot;HttpServlet methods. Click on the + sign on the left to edit the code.&quot;&gt;
      /**
       * Handles the HTTP &lt;code&gt;GET&lt;/code&gt; method.
       *
       * @param request servlet request
       * @param response servlet response
       * @throws ServletException if a servlet-specific error occurs
       * @throws IOException if an I/O error occurs
       */
      @Override
      protected void doGet(HttpServletRequest request, HttpServletResponse response)
              throws ServletException, IOException {
          processRequest(request, response);
      }
  
      /**
       * Handles the HTTP &lt;code&gt;POST&lt;/code&gt; method.
       *
       * @param request servlet request
       * @param response servlet response
       * @throws ServletException if a servlet-specific error occurs
       * @throws IOException if an I/O error occurs
       */
      @Override
      protected void doPost(HttpServletRequest request, HttpServletResponse response)
              throws ServletException, IOException {
          processRequest(request, response);
      }
  
      /**
       * Returns a short description of the servlet.
       *
       * @return a String containing servlet description
       */
      @Override
      public String getServletInfo() {
          return &quot;Short description&quot;;
      }// &lt;/editor-fold&gt;
  
  }
  </code></pre>
  <p>build file:</p>
  <pre><code>/*
   * This file was generated by the Gradle 'init' task.
   *
   * This generated file contains a sample Java Library project to get you started.
   * For more details take a look at the Java Libraries chapter in the Gradle
   * User Manual available at https://docs.gradle.org/6.5/userguide/java_library_plugin.html
   */
  
  plugins {
      // Apply the java-library plugin to add support for Java Library
      id 'java-library'
      id 'war'
  //    id 'org.gretty'
  }
  
  repositories {
      // Use jcenter for resolving dependencies.
      // You can declare any Maven/Ivy/file repository here.
      jcenter()
  }
  
  dependencies {
      // This dependency is exported to consumers, that is to say found on their compile classpath.
      api 'org.apache.commons:commons-math3:3.6.1'
  
      // This dependency is used internally, and not exposed to consumers on their own compile classpath.
      implementation 'com.google.guava:guava:29.0-jre'
  
      // Use TestNG framework, also requires calling test.useTestNG() below
      testImplementation 'org.testng:testng:7.2.0'
  
  
      providedCompile 'javax.servlet:javax.servlet-api:3.1.0' 
      testCompile 'junit:junit:4.12'
      
      
      // https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api
     //  providedCompile group: 'javax.servlet', name: 'javax.servlet-api', version: '3.0.1'
  
      
      
  
  }
  
  test {
      // Use TestNG for unit tests
      useTestNG()
  }
  </code></pre>
  <p>Probably just needs an addition for the <code>MANIFEST.MF</code> file?</p>
  <p>tree for the project:</p>
  <pre><code>hello_jsp/
  ├── build.gradle
  ├── gradle
  │   └── wrapper
  │       └── gradle-wrapper.properties
  ├── gradlew
  ├── gradlew.bat
  ├── LICENSE
  ├── README.md
  ├── settings.gradle
  └── src
      └── main
          └── java
              └── servlets
                  └── NewServlet.java
  
  6 directories, 8 files
  </code></pre>
  <p>It's just a very basic hello-world web app for servlets and JSP's.</p>