Auto-reloading changes in Maven
We need to do many changes in the code during development and it is really annoying when we have to restart the server after every little change.
We will explore ways of enabling auto-reloading in a Maven project when we use the Jetty web server. Why Jetty? It is because Jetty is lightweight and a quick container that is just perfect for application development.
How to do it…
We add the scanIntervalSeconds
configuration element that defines the number of seconds after Jetty checks for the changes in the classpath:
<plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <configuration> <scanIntervalSeconds>2</scanIntervalSeconds> </configuration> </plugin>
Alternatively, we just define we want to use the Jetty plugin and can set the scan interval in the Maven command when starting up the Jetty web server:
mvn -Djetty.reload=automatic -Djetty.scanIntervalSeconds...