Как использовать gradle
в для создания развертываемого WAR
файла, в частности, с правильным MANIFEST.MF
файлом?
полученным WAR
файлом:
[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]$
Однако, как и выше, MANIFEST.MF
на самом деле пусто.
пример сервлета:
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 <code>GET</code> and <code>POST</code>
* 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("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
/* TODO output your page here. You may use following sample code. */
out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet NewServlet</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet NewServlet at " + request.getContextPath() + "</h1>");
out.println("</body>");
out.println("</html>");
}
}
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/**
* Handles the HTTP <code>GET</code> 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 <code>POST</code> 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 "Short description";
}// </editor-fold>
}
файл сборки:
/*
* 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()
}
Возможно, просто нужно дополнение для файла MANIFEST.MF
?
дерево для проекта:
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
Это просто очень базовое c веб-приложение hello-world для сервлетов и JSP s.