Short: I have a project that provides a war artifact which includes a servlet with annotations but no web.xml. If i try to use the war in jetty i always get only the directory listing of the war content but not the 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 nothing special i guess. When i use mvn jetty:run
everything is fine. After ensuring this the project is packed into a war-archive.
This war archive is used within another project that has to set up jetty within code. This is how its done:
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();
When executing this project the logs tell me that the war is found. But if i open the url http://localhost:8080/admin
i only see the listing of the war content (instead of 'Hi there').
Can someone point me to my failure?