【问题标题】:How to access class path resource from MuleStudio and Mule Maven Standalone?如何从 MuleStudio 和 Mule Maven Standalone 访问类路径资源?
【发布时间】:2014-05-15 00:31:33
【问题描述】:

如何使用 Groovy 脚本从 src/main/resources 访问类路径资源?以下脚本适用于 MuleStudio,但不适用于独立的 Mule Maven。有没有办法编写可以从 MuleStudio 和 Mule Maven 独立提取正确资源的脚本?

<scripting:component doc:name="Script">
    <scripting:script engine="Groovy"><![CDATA[
        def command = "src/main/resources/shellscript/shellscriptfile.sh"
        def cmd = command.execute()
        cmd.waitFor()]]>
    </scripting:script>
</scripting:component>

【问题讨论】:

  • 问题是MuleStudio中的类路径目录是projectDir/classes/src/main/resources/shellscript,但在Standalone中,构建的类路径是apps/projectDir/classes/shellscript。有没有办法编写一个 Groovy 脚本,可以自动确定包含 classes 文件夹的应用程序主目录是什么?

标签: maven groovy mule mule-studio


【解决方案1】:

您应该将命令作为类路径资源加载,而不是尝试构建适用于所有情况的路径:

def command = this.getClass().getResource('/shellscript/shellscriptfile.sh').path
def cmd = command.execute()
cmd.waitFor()

【讨论】:

  • 谢谢大卫。要补充的一件事。 Groovy 将其作为 URL 对象读取,并尝试在其上运行不存在的 execute() 方法。只需在末尾添加 .getPath() 即可使其成为可执行的 shell 脚本命令。 def command = this.getClass().getResource('/scripts/RequestReturnBatch.sh').getPath()def cmd = command.execute()cmd.waitFor()]]&gt;
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-05
  • 2017-08-30
  • 2017-02-19
  • 2011-04-22
  • 1970-01-01
相关资源
最近更新 更多