Search code examples
tomcatgwterraierrai-4

How can hot reload be enabled when running Errai on Tomcat?


I am developing a project with Errai 4 and as usual I can run "mvn gwt:run" and hot reload just works, i.e. I change models or views and I only need to refresh the browser.

Now I need that but running my Errai application on top of Tomcat 7.

The project with the Tomcat is similar to https://github.com/stbland/errai-tutorial-tomcat

The question is how to make hot reload work with Tomcat 7 when I am only making changes in the front-end using only mvn gwt:run or similar.

Step by step final solution:

Info for solve this:

Install the original project

For this example we will use the errai-tutorial

Run on Tomcat

Listening changes

  • cd errai-tutorial
  • mvn gwt:compile
  • mvn gwt:run

Now you can open http://localhost:8080/errai-tutorial/ in your web browser

For do hot reload you will need import this class in your project:

and call it in a shorcut of this way (SuperDevModeHelper.devModeOn()) like this:


Solution

  • Take a look to this archetype https://github.com/tbroyer/gwt-maven-archetypes/

    The modular-webapp configures tomcat and gwt to work together. Hot-reload works because gwt:codeserver generates a special bootstrapper (the your-app.nocache.js) that immediately run a gwt compile and reloads on completion. To make it work you need to load the gwt:codeserver generated launcherDir into the tomcat context, this is done in this archetype using the context.xml.

    Alternatively, you can add some compile-trigger into your own app so you can fire the compilation using a shortcut. This is all you need to fire a compilation (DevModeHelper). Just add a shortcut handler in your app entry point and call devModeOn(). If you don't want to add it in your final compilation, install the event listener only if System.getProperty("superdevmode").equals("on") is true. In this case, use the classic Dev Mode On bookmark the first time, then use your custom shortcut. We use this strategy and it works nicely.