简体   繁体   English

Grails 应用程序中 Groovy 代码的编译

[英]Compilation of Groovy Code in Grails application

When I build a war file for my Grails application via grails war it still contains some groovy files.当我通过grails war为我的 Grails 应用程序构建战争文件时,它仍然包含一些 groovy 文件。

After the war-filed is deployed on an application server, when and how are this files compiled to java bytecode?在应用服务器上部署war文件后,这些文件何时以及如何编译为java字节码?

The templates are there for dynamic scaffolding.模板用于动态脚手架。 For example if you have a controller like this例如,如果您有这样的 controller

class PersonController {
   static scaffold = Person
}

then it'll use the template to create a controller at runtime.然后它将使用模板在运行时创建 controller。 This isn't very often used in real apps - it's more for demos and getting started - but it's an option.这在实际应用程序中并不经常使用——它更多地用于演示和入门——但它是一种选择。 The dynamically generated controller and GSPs are created based on the templates and compiled in-memory.动态生成的 controller 和 GSP 基于模板创建并在内存中编译。

The groovy-all jar does have code that can compile Groovy source, but that's because it's the "-all" jar. groovy-all jar 确实有可以编译 Groovy 源代码的代码,但那是因为它是“-all” jar。 Just because it's there doesn't mean it's necessarily used.仅仅因为它在那里并不意味着它必须被使用。 In general all compilation is done when building the war, including precompiling GSPs.一般来说,所有编译都是在构建战争时完成的,包括预编译 GSP。 This is for performance - you want the app to be as fast as possible in production.这是为了性能 - 您希望应用程序在生产中尽可能快。

The groovy files are compiled into class files before you package into the war. groovy文件在package进入战争之前编译成class文件。 Check the WEB-INF/classes directory检查 WEB-INF/classes 目录

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM