What is the fastest way to deploy a Java HttpServlet
? Is there a solution that allows you to do it very quickly like I could do in Ruby/PHP/Python with mini
Check out embedded Jetty. The configuration is all done in Java so you don't have to dink with a bunch of configuration files. Its extremely fast -- it takes about 2 seconds to start and no IDE is required. I usually run it in a terminal and just bounce it when I make a change, though you may be able to configure it to dynamically reload your changes. If you scroll to the bottom of that link, you'll see details about configuring servlets.
Here is some example code from the Jetty wiki, the server code:
public class OneServletContext
{
public static void main(String[] args) throws Exception
{
Server server = new Server(8080);
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
server.setHandler(context);
context.addServlet(new ServletHolder(new HelloServlet()),"/*");
context.addServlet(new ServletHolder(new HelloServlet("Buongiorno Mondo")),"/it/*");
context.addServlet(new ServletHolder(new HelloServlet("Bonjour le Monde")),"/fr/*");
server.start();
server.join();
}
}
And a sample servlet:
public class HelloServlet extends HttpServlet
{
private String greeting="Hello World";
public HelloServlet(){}
public HelloServlet(String greeting)
{
this.greeting=greeting;
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
response.setContentType("text/html");
response.setStatus(HttpServletResponse.SC_OK);
response.getWriter().println(""+greeting+"
");
response.getWriter().println("session=" + request.getSession(true).getId());
}
}