Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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?

like image 562
Dominik Avatar asked Jul 16 '11 18:07

Dominik


2 Answers

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

like image 70
bcoughlan Avatar answered Sep 27 '22 20:09

bcoughlan


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>
like image 40
carlspring Avatar answered Sep 27 '22 18:09

carlspring