0
我有隨附的grails腳本,我在互聯網上的一些隨機地方找到它,它在啓動grails環境中啓動腳本時工作得很好。它似乎沒有做的唯一的事情是啓動我的conf/*Bootstrap.groovy
腳本,就像我做run-app時一樣。如何完全引導Grails環境?
是否有另一個功能,如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()
}
}
是啊..你必須做在一個腳本在同一ScriptEngine的運行..它贏得了」 t在右邊的gant腳本中運行,如圖所示。 我剛剛添加了一個Init.groovy,它可以調用任何引導程序的東西,並在腳本引擎的相同實例中運行它,我運行實際腳本。 謝謝! – danb 2009-06-03 16:38:42