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("<h1>"+greeting+"</h1>");
response.getWriter().println("session=" + request.getSession(true).getId());
}
}
The fastest way is using your IDE of choice, of course. As for the minimal configuration, check out WebServlet annotation which appeared in Servlet 3.0 API. Using this annotation, you don't need any to add any additional information to web.xml.
Have you looked at Grails? It's basically Groovy on Rails, the bytecode is Java if that counts.
Also look at this article about One-step deployment with Grails
In Eclipse you can effectively run the servlet directly from your workspace - it links quite cleanly to TomCat or WebSphere CE. Pretty much edit/save (auto compile)/ debug/
Check out JRebel.