5

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?

sthomps
  • 4,480
  • 7
  • 35
  • 54
  • Hi, I face the same problem. But what do you mean by Ctrl+C to kill the dev server? How do I do this? Ctrl+C in the console? – user3259937 Mar 30 '15 at 06:24
  • @user3259937, Ctrl+C is command used on windows to abort running process on Command Prompt or Maven shell. So that you can start server again by 'mvn appengiine:devserver' – Pratap Singh Jan 16 '20 at 05:43

4 Answers4

3

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)

Patrice
  • 4,641
  • 9
  • 33
  • 43
  • 1
    Ah, that sucks to hear. It makes the developer workflow much slower having to manually stop and start the dev server every time I want to try a new code change. – sthomps Jul 31 '14 at 04:44
  • yeah it's really unfortunate. It comes from the fact that python is interpreted while java is compiled I guess. But I get you, it really sucks to push your whole code to dev server for a small change – Patrice Jul 31 '14 at 12:57
  • It would be nice if the java dev server could detect code changes, shut itself down, recompile and start itself back up again. Wouldn't be as fast as python but that would save a lot hassle in the workflow. I almost went with Go because it supports this iterative development but unfortunately has no support for Cloud Endpoints. – sthomps Jul 31 '14 at 14:52
  • yeah it would be a nice feature for them to add in their SDK. I'm not sure they will though :( One can only hope – Patrice Jul 31 '14 at 14:56
1

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.

Don McCurdy
  • 10,975
  • 2
  • 37
  • 75
1

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.

Neill
  • 556
  • 2
  • 8
  • 18
  • Hi @Neill, Can you elaborate a little more on your answer, the project setup i have is what exactly you had mentioned. So if you can give insights those details, on how you achieved it, that would be helpful for me. – Sasi Dunston Sep 07 '18 at 14:18
  • `explodeWar` is a better gradle task to update running server, see here: https://cloud.google.com/appengine/docs/standard/java/tools/gradle – Juozas Kontvainis Oct 06 '18 at 11:13
0

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.

timmacp
  • 191
  • 1
  • 13