Loading external groovy script while using camunda engine .jar file


I am trying to load an external groovy script in my BPMN and I can’t find any way to do this. It is important to mention I am running a Camunda engine from a .jar file so I can’t put my groovy script to META-INF.

My setup:

  1. Run Camunda engine from compiled .jar sudo java -cp "home/e/h2/bin/h2-1.4.199.jar" -jar -Dspring.profiles.active="local" camunda-compiled.jar
  2. Put together a BPMN file with a Script task using External script script1.groovy
  3. Deploy BPMN to the started engine
  4. After starting an instance of the process I get an error when the process comes to the Script tast defined in step number 2 saying it can’t load script1.groovy.

I have tried to put my script1.groovy to the same directory as my .bpmn process. Also I tried to specify an extra classpath sudo java -cp "/home/e/groovy_scripts/script1.groovy;/home/e/h2/bin/h2-1.4.199.jar" -jar -Dspring.profiles.active="local" camunda-compiled.jar. Nothing has worked.

I have tried using load function as one forum topic suggested, but I had no success using it. (I put load(‘classpath:script1.groovy’) as the script task inline script as well as external task…)

Is there a way to load an external script, please?

Hello erhan
You can refer you extenal script as classpath resource. Just add configure ScriptTask with “Script Type => External Resource” and specify Resource with prefix “classpath://”.

<scriptTask scriptFormat="groovy" camunda:resource="classpath://org/myproject/bpm/task.groovy"/>

Hi, Roman,
this approach does not work for me. Camunda engine does not find the script Caused by: org.camunda.bpm.engine.exception.NotFoundException: ENGINE-09024 Unable to find resource at path classpath://script1.groovy .

<bpmn:scriptTask id="ScriptTask_1nvpkgh" name="Script 1 - Test" scriptFormat="groovy" camunda:resource="classpath://script1.groovy">

I guess this way would work in case I would put the groovy script inside Camunda java project. But I execute Camunda engine from a .jar file and then only deploy a .bpmn to it.

Hello Erhan

  1. At the command line should be classpath for the folder where do you have your scripts (not the script). Try this: java -cp "/home/e/groovy_scripts/;home/e/h2/bin/h2-1.4.199.jar"

  2. I think, deployed scripts are referenced with prefix deployment://. See ResourceUtil.java

OK, I figured it out. I started the Camunda application wrong. org.springframework.boot.loader.PropertiesLauncher had to be used:

sudo java -cp "camunda-compiled.jar:/home/e/h2/bin/h2-1.4.199.jar:/home/e/groovy_scripts" -Dspring.profiles.active="local" org.springframework.boot.loader.PropertiesLauncher