0
私は、インターネット上のいくつかのランダムな場所にあるgrailsスクリプトを用意しています。これは、ブートストラップされたgrails envでスクリプトを起動するためにはうまくいきます。それは私がrun-appをするときのように私のconf/*Bootstrap.groovy
スクリプトをキックオフするだけではないようです。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()
}
}
を試してみてください...それは勝ちました図のようにgantスクリプトを実行してください。 私はブートストラップのものを呼び出すことができるInit.groovyを追加しました。実際のスクリプトを実行するスクリプトエンジンの同じインスタンスで実行します。 ありがとう! – danb