-1

I have a Maven WebApp project in which i am continuously changing my servlet class, Whenever i change my servlet class i to have re-run the project by clean package and tomcat:run, if i don't re-run, it doesn't show changes on webapp what i change in servlet class, Is there any fast method to update my project instead of re-run the project because it takes a lot of time to re-run.

I am using eclipse ide for running my project, so please give me solution based on eclipse.

Suppose that's my servlet classs

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class Login_Bridge
 */
@WebServlet("/abc")
public class abc extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public abc() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub

        System.out.println("hello");
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        System.out.println("hello1");

    }

}

Suppose i add another System.out.println("Hello2") in my get method, and when i refresh my page on browser it doesnot show any changes but when i re-run the project by (clean package) then (tomcat:run), then it shows changes on browser so my question is, Is there any other method to do this in a fast way so that i can see changes in fast way.

Massnk Dev
  • 19
  • 1
  • 6

1 Answers1

1

You may use the hot Deploy feature in eclipse StackOverflow answer. But if you are trying to debug your application I'd suggest you to use unit testing instead.

It's much more convenient than hot deployment.

example:

@Mock
private HttpServletRequest request;
@Mock       
private HttpServletResponse response;

private YourServletClass sut;

@Before
public void initTest(){
    MockitoAnnotations.initMocks(this);
    //Init your mocks as yuou wish
    when(request.getParameter("parameter1")).thenReturn("Param1Value");
    when(request.getParameter("parameter2")).thenReturn("Param2Value");
    sut = new YourServletClass();
}


@Test
public void testMyServlet() throws Exception {
    sut.doPost(request, response);
    verify( /*....*/ );
}
Community
  • 1
  • 1
snovelli
  • 5,804
  • 2
  • 37
  • 50