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

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

问题描述

我很好奇,有没有人知道Grails或Play等框架如何检测代码中的更改并自动触发重新编译而无需重新启动应用程序服务器?有什么特定于Groovy的编译器或其动态特性,允许这很容易发生?



为了背景,我有一个自定义的代码生成阶段,在我的构建过程中,我会爱能够具有类似的编辑和刷新功能。



预先感谢任何指针,即使我必须筛选代码才能获得更大的图片。



编辑:我应该澄清一下,我不打算在任何情况下编译Grails插件以了解如何执行此操作应用程序在一个servlet容器中。即,我正在使用Groovy,但不使用Grails。



Edit2:听起来像Play有一个特定的DEV模式, http://www.playframework.org/documentation/1.1.1/main#lifecycle



据我所知,JRebel通过类加载器执行了精细的类版本控制,但我假设像Grails或Play这样的Web框架并没有将它带入该级别。

解决方案

使用Eclipse JDT在运行时编译代码时播放它。



看看下面这个类,它被Play用来在运行时执行必要的编译。



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



另外,请注意Play中DEV模式与PROD模式的区别。这是由Play开发人员做出的设计决定,一旦应用程序进入Production模式,这些类将在服务器启动时编译,并且不会检查热重载。这是有道理的,因为在PROD模式下,你的代码不应该真的在改变。



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

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.

Edit: 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: It sounds like Play has a specific DEV mode which enables this hot reloading: http://www.playframework.org/documentation/1.1.1/main#lifecycle

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 does it using the Eclipse JDT to compile code at run-time.

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

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.

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天全站免登陆