简体   繁体   中英

How to access class path resource from MuleStudio and Mule Maven Standalone?

How do you access a class path resource from src/main/resources with a Groovy script? The following script works in MuleStudio, but does not work in Mule Maven standalone. Is there a way to write the script where it can pull the correct resource from MuleStudio and Mule Maven standalone?

<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>

You should load the command as a classpath resource instead of trying to build a path that works in all cases:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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