java Jetty 自动刷新/自动加载以进行快速测试
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6719406/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Jetty autorefresh/autoload for quick testing
提问by Dominik
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?
从 PHP 开始,我习惯于.php
在修改源文件后保存文件并重新加载浏览器。我怎样才能用 JAVA 和 Jetty 做到这一点?当我保存我的网络服务时,我当前停止了码头服务器并用 重新启动它mvn jetty:start
,到达我想去的地方的简单方法是什么?
采纳答案by carlspring
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.
好吧,PHP 和 Java 之间的区别在于,前者是解释器,而后者是基于编译器的(二进制)。在 PHP 中,代码在执行时进行验证,而在 Java 中,您需要先编译它。在 Java 中,当您使用 JSP-s 时,可以通过点击浏览器中的刷新按钮来保存它们并重新加载它们(当然,如果它在开发模式下运行)。如果更改类,则需要重新启动服务器。如果您只是更改 Web 资源,则只需scanInterval
为 Jetty Maven 插件定义变量即可。这将负责更新您的网络资源。
[EDITED] Added the code from Hyman Murphy's comment below, so that it is correctly formatted.
[已编辑] 从下面的 Hyman Murphy 的评论中添加了代码,以使其格式正确。
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<configuration>
<scanIntervalSeconds>2</scanIntervalSeconds>
</configuration>
</plugin>
回答by bcoughlan
From the command line:
从命令行:
mvn -Djetty.reload=automatic -Djetty.scanIntervalSeconds=2 jetty:run
If you are depending on Eclipse, ensure you have Project->Build Automaticallyenabled so that the classes are recompiled.
如果您依赖 Eclipse,请确保已启用Project->Build Automatically,以便重新编译类。
I haven't tried the configuration file approach, but more details of Hyman Murphy's approach can be found here: http://docs.codehaus.org/display/JETTY/Maven+Jetty+Plugin
我还没有尝试过配置文件方法,但可以在此处找到有关 Hyman Murphy 方法的更多详细信息:http: //docs.codehaus.org/display/JETTY/Maven+Jetty+Plugin
回答by Xinbo
A late answer. in IntelliJ, the Resource/class/front end modification can be refresh without restart server by following steps.
迟到的答案。IntelliJ中Resource/class/前端的修改可以在不重启服务器的情况下按照以下步骤进行刷新。
1: Edit 'On Update Action' section in server configuration.
2: Every time when you did above modification. Click the last button.
2:每次进行上述修改时。单击最后一个按钮。
And refresh browser. That's it.
并刷新浏览器。而已。