有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何自动重新加载应用程序引擎开发服务器?

我在跟踪tutorial on the App Engine website for 'Google Cloud Endpoints' in Java。一切正常,我可以使用mvn appengine:devserver运行开发服务器。问题是,当我对文件(例如,任何java文件)进行任何更改时,开发服务器不会自动重新编译。我需要按住ctrl-c键来关闭dev服务器,并在每次代码更改时重新启动它

有没有办法让maven自动检测对项目中任何文件的更改,并让它自动重建和重新启动开发服务器


共 (3) 个答案

  1. # 1 楼答案

    不幸的是,没有。如果您想在dev服务器上实现这种行为,您需要使用Python

    我也遇到过同样的问题,应用程序引擎并没有提供真正的解决方法来帮助您做到这一点

    从“为Eclipse使用Google插件”中:

    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

    Java中没有可比性(来自“Java开发服务器”的链接)(https://developers.google.com/appengine/docs/java/tools/devserver

  2. # 2 楼答案

    我发现使用Gradle、GAE和springmvc,assemble命令将正确的工件放置到位,服务器将重新初始化应用程序。这比服务器重启要快一点

  3. # 3 楼答案

    目前,AppEngineSDK中没有任何东西可以在文件更改时自动重新启动,但这并不是说您不能这样做。我遇到了同样的问题,并编写了一个脚本,以侦听文件更改作为重新启动应用程序引擎的触发器。它是用JavaScript编写的,所以如果还没有,您需要install Node.js

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

    这将立即启动应用程序引擎,然后在文件更改时重新启动它。如果应用程序因某种原因崩溃,脚本将在尝试重新启动之前等待您的下一次编辑


    另外,整个脚本大约有40行代码,你可以在其他脚本语言中做同样的事情。如果您以前没有尝试过编写自己的自动化,我绝对建议您查看source code,看看它是如何工作的