简体   繁体   English

如何完全引导Grails环境?

[英]How do I completely bootstrap a grails environment?

I have the included grails script that I found in some random place on the internet and it works pretty well for firing up scripts in a bootstrapped grails env. 我有包含的grails脚本,可以在Internet上的某个随机位置找到它,它对于在自举的grails env中启动脚本非常有效。 The only thing it doesn't seem to do is kick off my conf/*Bootstrap.groovy scripts like when I do run-app. 似乎唯一没有做的就是像运行run-app一样启动conf/*Bootstrap.groovy脚本。

Is there another function like loadApp() and configureApp() that will do that for me? 是否有另一个功能如loadApp()configureApp()可以为我完成此工作?

import org.codehaus.groovy.grails.support.PersistenceContextInterceptor

Ant.property(environment: "env")
grailsHome = Ant.antProject.properties."env.GRAILS_HOME"

includeTargets << new File("${grailsHome}/scripts/Bootstrap.groovy")

target('default': "Runs scripts in the test/local directory") {
    if (!args) { throw new RuntimeException("[fail] This script requires an argument - the script to run.") }

    depends(configureProxy, packageApp, classpath)
    classLoader = new URLClassLoader([classesDir.toURI().toURL()] as URL[], rootLoader)
    Thread.currentThread().setContextClassLoader(classLoader)
    loadApp()
    configureApp()

    def interceptor = null
    def beanNames = appCtx.getBeanNamesForType(PersistenceContextInterceptor)
    if (beanNames && beanNames.size() == 1) {
        interceptor = appCtx.getBean(beanNames[0])
    }
    try {
        interceptor?.init()
        new GroovyScriptEngine(Ant.antProject.properties."base.dir", classLoader).run("scripts/${args}.groovy", new Binding(['appCtx':appCtx]))
        interceptor?.flush()
    } catch (Exception e) {
        e.printStackTrace()
        interceptor?.clear()
    } finally {
        interceptor?.destroy()
    }
}

Yes, try 是的,尝试

new BootStrap().init() 新的BootStrap()。init()

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

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