'How to auto reload app engine dev server?

Im following the tutorial on the App Engine website for 'Google Cloud Endpoints' in Java. Everything works fine and I can run the development server using mvn appengine:devserver. The problem is that when I make any changes to a file (for example, any java file) the dev server doesnt automatically recompile. I need to ctrl-c to kill the dev server and restart it for every code change I make.

Is there a way to have maven automatically detect changes to any files in my project and have it automatically rebuild and restart the dev server?



Solution 1:[1]

Unfortunately no. If you want this behavior on your dev server, you need to use Python.

I run in the same issue and there is no real workaround provided by the App Engine to help you doing this.

From the "Using The Google plugin for Eclipse":

With Eclipse, you can leave the server running in the debugger while you make changes to source code, JSPs, static files and appengine-web.xml. When you save changes to source code, Eclipse compiles the class automatically, then attempts to insert it into the running web server dynamically. In most cases, you can simply reload the page in your browser to test the new version of the code. Changes to JSPs, static files and appengine-web.xml are recognized by the development server automatically, and also take effect without restarting the server. If you change web.xml or other configuration files, you must stop and start the server for the changes to take effect.

(https://developers.google.com/appengine/docs/java/tools/eclipse#Running_the_Project)

There is NOTHING comparable in Java (link from "The Java Development Server") (https://developers.google.com/appengine/docs/java/tools/devserver)

Solution 2:[2]

There's currently nothing in the App Engine SDK to automatically restart when files change, but that's not to say you can't do it. I ran into the same problem and wrote up a script to listen for file changes as triggers to restart App Engine. It's in JavaScript, so you'll need to install Node.js if you haven't already.

// Install watch-exec
$ npm install -g watch-exec

// Watch the current directory
$ watch-exec --command "mvn appengine:devserver" --watch .

This will immediately start App Engine, and then restart it any time a file changes. If the app crashes for some reason, the script will wait for your next edit before trying to restart.


P.S. That entire script is about 40 lines of code, and you could probably do the same thing in other scripting languages. If you haven't tried writing your own automation before, I'd definitely recommend checking out the source code to see how this works.

Solution 3:[3]

I've found using Gradle, GAE, and Spring MVC, the assemble command will put the correct artifacts in place, and the server will re-init the app. It's a little quicker than a server restart.

Solution 4:[4]

Using App Engine standard with the cloud.tools appengine-maven-plugin hot swap works fine (most of the time, can be problems when setting up the workspace). For a multi-module maven project: no need to stop the server or browser, just push the code changes (maven command package -pl *-server) & refresh the browser. Debugging with a debug client currently works perfectly for changing / adding code within methods.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Don McCurdy
Solution 3 Neill
Solution 4 timmacp