Jetty autorefresh/autoload for quick testing
From PHP I am used to just saving the .php
file and reloading the browser after modifying the source file.开发者_StackOverflow How can I do this with JAVA and Jetty? When I save my webservice I currently stop the jetty server and start it again with mvn jetty:start
, whats the non-complicated way of getting where I want to go?
From the command line:
mvn -Djetty.reload=automatic -Djetty.scanIntervalSeconds=2 jetty:run
If you are depending on Eclipse, ensure you have Project->Build Automatically enabled so that the classes are recompiled.
I haven't tried the configuration file approach, but more details of Jack Murphy's approach can be found here: http://docs.codehaus.org/display/JETTY/Maven+Jetty+Plugin
Well, the difference between PHP and Java is that the former is an interpreter, whereas the latter is compiler-based (binary). In PHP the code is validated upon execution, whereas in Java you need to compile it first. In Java, when you use JSP-s, it is possible to just save them and reload them by hitting the refresh button in your browser (if, of course, it's running in development mode). If you change classes, you need to restart your server. If your're just changing web resources, you can simply define the scanInterval
variable for the Jetty Maven plugin. That will takes care of updating your web resources.
[EDITED] Added the code from Jack Murphy's comment below, so that it is correctly formatted.
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<configuration>
<scanIntervalSeconds>2</scanIntervalSeconds>
</configuration>
</plugin>
A late answer. in IntelliJ, the Resource/class/front end modification can be refresh without restart server by following steps.
1: Edit 'On Update Action' section in server configuration.
2: Every time when you did above modification. Click the last button.
And refresh browser. That's it.
精彩评论