The Coder
The Coder

Reputation: 2632

How to make Maven automatically recompile if Changes are detected?

I was doing some project in spring mvc and using mvn jetty as runtime environment and also the entire workspace is within Eclipse. I've already seen in servlets which uses tomcat as runtime, that if any changes are made in Java files, those files are automatically recompiled within eclipse which prevents us from restarting the tomcat again saving up lot of time.

But here in maven, it compiles the files to target folder, any changes in jsp are immediately reflected except few cases, but changes in Java files are not automatically recompiled until I use mvn jetty:run again. This consumes lot of time even after skipping tests, is there any configurations to make maven automatically recompile the changed java files or I should have to run mvn jetty:run again and again for every change..? Thanks

Edit : I'm using mvn jetty:run within the eclipse, not using external terminals

Upvotes: 5

Views: 6276

Answers (2)

Paul Samsotha
Paul Samsotha

Reputation: 208994

You just need to set the scanIntervalSeconds property in the plugin

scanIntervalSeconds

  • The pause in seconds between sweeps of the webapp to check for changes and automatically hot redeploy if any are detected. By default this is 0, which disables hot deployment scanning. A number greater than 0 enables it.

Basically something like

<plugin>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>${jetty.version}</version>
    <configuration>
        <contextPath>/</contextPath>
        <stopKey>foo</stopKey>
        <stopPort>9999</stopPort>
        <scanIntervalSeconds>5</scanIntervalSeconds>
    </configuration>
</plugin>

I use this all the time. Works fine. The above will scan for any changes every 5 seconds. And yes, even your Java files.

Also when the scanning is done, you should see some update in the console, if the change is picked up in that time interval. If you don't see any updates, it's possible that particular file isn't picked up (though Java files should be picked up, I'm just talking about other files in general). If that's the case, you can specify the <scanTargets> explicitly

scanTargets

  • Optional. A list of files and directories to periodically scan in addition to those the plugin automatically scans.
<configuration>
    ...
    <scanTargets>
        <scanTarget>path/to/somefile</scanTarget>
    </scanTargets>
</configuration>

Upvotes: 1

CNiq527
CNiq527

Reputation: 21

Maybe you could use Run-Jetty-Run eclipse plugin.

https://code.google.com/p/run-jetty-run/wiki/UserGuide Section How to work with Java hot-deploy http://code.google.com/p/run-jetty-run/wiki/RunMavenWebAPP

Upvotes: 0

Related Questions