Grails 或 Play 如何检测更改和热重载类? [英] How do Grails or Play detect changes and hot reload classes?

查看:24
本文介绍了Grails 或 Play 如何检测更改和热重载类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好奇有人知道 Grails 或 Play 等框架如何检测代码中的更改并自动触发重新编译而无需重新启动应用程序服务器的详细信息吗?是否有特定于 Groovy 的编译器或其动态性质的某些东西使这种情况很容易发生?

I'm curious does anyone know the details on how frameworks like Grails or Play detect changes in the code and automatically trigger a recompilation without rebooting the app server? Is there something specific to Groovy's compiler or its dynamic nature that allows this to easily happen?

作为背景,我在构建过程中有一个自定义代码生成阶段,我希望能够拥有类似的编辑和刷新功能.

For background, I have a custom code generation stage during my build process that I would love to be able to have similar edit-and-refresh capabilities.

提前感谢您的指点,即使我必须筛选代码才能获得更大的图片.

Thanks in advance for any pointers, even if I have to sift through code to get the larger picture.

我应该澄清一下,我不打算构建 Grails 插件,而是要了解在 servlet 容器中的任何应用程序中执行此操作需要什么.即,我使用的是 Groovy 而不是 Grails.

I should clarify that I'm not looking to build a Grails plugin so much as understand what it takes to do this in any app in a servlet container. i.e., I'm using Groovy but not Grails.

Edit2: 听起来 Play 有一个特定的 DEV 模式可以启用这种热重载:http://www.playframework.org/documentation/1.1.1/main#lifecycle

It sounds like Play has a specific DEV mode which enables this hot reloading: http://www.playframework.org/documentation/1.1.1/main#lifecycle

我知道 JRebel 通过类加载器执行复杂的类版本控制,但我假设像 Grails 或 Play 这样的网络框架没有达到那个水平.

I understand that JRebel performs elaborate class versioning via classloaders, but I'm assuming that web frameworks like Grails or Play aren't taking it to that level.

推荐答案

Play 使用 Eclipse JDT 在运行时编译代码.

Play does it using the Eclipse JDT to compile code at run-time.

看看下面的类,Play 使用它在运行时执行必要的编译.

Take a look at the following class, that is used by Play to perform the necessary compilation at run time.

https://github.com/playframework/play/blob/master/framework/src/play/classloading/ApplicationCompiler.java

另外,只是要注意 Play 中 DEV 模式和 PROD 模式之间的区别.这是 Play 开发人员做出的设计决定,一旦应用程序进入生产模式,在服务器启动时编译类,并且不会检查热重载.这是有道理的,因为在 PROD 模式下,您的代码不应该真正改变.

Also, just to note the difference between the DEV mode and PROD mode in Play. This is a design decision made by the Play developers that once an application is put into Production mode, the classes are compiled when the server starts, and are not checked for hot-reloading. This makes sense because in PROD mode, your code should not really be changing.

在 DEV 模式下,每次收到新请求时都会检查 Java 文件是否有更新,任何更改的文件都会自动重新编译(错误会直接显示在浏览器中).这个过程在 DEV 模式下非常高效,因为你会经常更改代码,而且即时反馈非常强大.

In DEV mode, Java files are checked for updates each time a new request is received, and any changed files are automatically recompiled (and errors displayed directly in the browsers). This process is very productive in DEV mode, because you will be changing code often, and the immediate feedback is very powerful.

这篇关于Grails 或 Play 如何检测更改和热重载类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆