Maven Embedded Tomcat automatic redeploy

How to automatically redeploy embedded Tomcat if you change some Java class?

If you run embedded Tomcat using goal tomcat7:run, you will notice that when you change some Java class (for example a Servlet), the application won't automatically redeploy, so you will have to stop the whole server and run it again.


To change that go to pom.xml and add this configuration to the tomcat plugin:




Next create a context.xml file:


<Context reloadable="true" backgroundProcessorDelay="1">


And finally restart the server. And now if you change something in some Java class, the Tomcat will redeploy the application automatically.



Also if you use STS (Spring Tool Suite), in latest versions you have this Relaunch button, which will restart the server.