Question

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>
Was it helpful?

Solution

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()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top