The fastest way to deploy a Java servlet?

What is the fastest way to deploy Java HttpServlet ? Is there a solution that allows me to do this very quickly, as I could do in Ruby / PHP / Python with minimal configuration?

I need something that will allow me to quickly start servlets and swap them during the debug cycle. I'm not very good at Java, especially when it comes to deployment.

I don’t want to configure it for hours, mess with configuration files and sort dependencies. I just want something that I can install and run. Something less enterprise-oriented.

I am not using an IDE.

Is there something that can reduce deployment to just run something in a terminal, like with Ruby. Something that is not painful. Something that doesn't make me want to jump out of the window. Without trillions of XML files.

The best option so far is to transfer the whole idea of ​​a "servlet" and deploy it to an HTTP server with Java support. It seems about 1000 times easier than anything related to servlets.

+4
source share
5 answers

Embedded Jetty opens. The configuration is done in Java, so you do not need to write a bunch of configuration files. Its very fast - it takes about 2 seconds, and no IDE is required. I usually run it in the terminal and just discard it when I make changes, although you can configure it to dynamically reload changes. If you go to the bottom of this link, you will see detailed information about configuring servlets.

Here is a sample code from the Jetty wiki server, 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 an example of a 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()); } } 
+3
source

Check out JRebel .

+2
source

Have you watched Grails ? This is basically Groovy on Rails, bytecode is Java, if that counts.

Also check out this article on One-Step Deployment with Grails

+1
source

In Eclipse, you can efficiently run a servlet directly from a workspace β€” it is pretty cleanly connected to TomCat or WebSphere CE. Pretty much editing / saving (auto-compiling) / debug /

+1
source

The fastest way is, of course, using your IDE. For a minimal configuration, see the WebServlet annotation that appeared in the Servlet 3.0 API. Using this annotation, you do not need to add any additional information to web.xml.

+1
source

All Articles