Short: I have a project that provides a war artifact that includes a servlet with annotations, but not web.xml. If I try to use war at the pier, I always get only a list of directories of military content, but not servlet execution.
Any idea?
Long story: My servlets look like this:
package swa; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @WebServlet( asyncSupported = false, urlPatterns={"/*"}) public class ServletX extends HttpServlet { private static final long serialVersionUID = 1L; public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // Set response content type response.setContentType("text/html"); // Actual logic goes here. PrintWriter out = response.getWriter(); out.println("<h1>Hi there..</h1>"); } }
So I donβt think anything special. When I use mvn jetty:run , everything is fine. Making sure that the project is packaged in a military archive.
This military archive is used in another project, which should establish a berth in the code. Here's how to do it:
String jettyPort = properties.getProperty("jetty.port", "8080"); Server server = new Server(); ServerConnector httpConnector = new ServerConnector(server, new HttpConnectionFactory()); httpConnector.setPort(Integer.parseInt(jettyPort)); httpConnector.setAcceptQueueSize(2); httpConnector.setHost("0.0.0.0"); httpConnector.setIdleTimeout(30000); server.setConnectors(new Connector[] { httpConnector }); WebAppContext wacHandler = new WebAppContext(); wacHandler.setContextPath("/admin"); wacHandler.setWar("swa-0.0.1-SNAPSHOT.war"); wacHandler.setConfigurationDiscovered(true); server.setHandler(wacHandler); server.start();
During this project, magazines tell me that a war has been found. But if I open the url http://localhost:8080/admin , I only see a list of military content (instead of "Hello there").
Can someone point me to my refusal?
java annotations servlets jetty embedded-jetty
kDot
source share