【问题标题】:GroovyScriptEngine roots or url parameter confusionGroovyScriptEngine 根目录或 url 参数混淆
【发布时间】:2014-01-17 17:36:42
【问题描述】:

我正在企业 Java 应用程序中尝试 Groovy。在应用程序中,Spring 被大量使用。我从单元测试开始,看看如何初始化 GroovyScriptEngine。项目结构有点复杂。我会尽量让它简单。 module1module2module3 是 maven 模块。 module0 是根模块,是所有模块的父模块。

在 JUnit 中,我这样称呼它:

GroovyScriptEngine groovyScriptEngine = new GroovyScriptEngine("module1/module2/module3/src/main/resources/META-INF/scripts");

此字符串参数以
D:/myProjects/module0/module1/module2/module3/src/main/resources/META-INF/scripts 的形式转到GroovyScriptEngineroots 字段。

到目前为止,这不是问题。 我部署了应用程序。像这样定义url 参数:

<bean id="groovyScriptEngine" class="groovy.util.GroovyScriptEngine">
    <constructor-arg name="url" value="${core.groovy.roots}"/>
</bean>

在哪里
core.groovy.roots=module1/module2/module3/src/main/resources/META-INF/scripts

在初始化时,我正在跟踪 url 参数,它会像这样进入同一个地方:

D:/servers/tools/apache-tomcat-6.0.32/bin/module1/module2/module3/src/main/resources/META-INF/scripts

我也尝试将classpath*:/META-INF/scripts 赋予相同的参数,但它也不起作用:

D:/servers/tools/apache-tomcat-6.0.32/bin/classpath*:/META-INF/scripts

我怎样才能使参考相对并使其工作?

谢谢。

【问题讨论】:

    标签: spring groovy classpath


    【解决方案1】:

    您可以使用其他 Java 源代码编译 Groovy 代码,而不是使用 GroovyScriptEngine,并像使用任何其他 Java 类一样使用它。

    GroovyScriptEngine 在需要动态解释 Groovy 代码并且在脚本更改后无需重新启动应用程序时才有意义。例如,您可以拥有外部脚本源。

    【讨论】:

    • 感谢您的评论,但情况就像您说的一样。我需要脚本的动态行为。
    猜你喜欢
    • 2016-08-13
    • 2011-12-21
    • 2021-10-07
    • 1970-01-01
    • 2018-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-23
    相关资源
    最近更新 更多