DNM Scripting

In the documentation it states groovy, python and ruby can be used. It shows which dependency is required for groovy but not python and ruby.

What is required for python? Just PYTHON_HOME?

Thanks.

Hi,

You need Jython on the DMN engine’s classpath. See http://mvnrepository.com/artifact/org.python/jython/2.7.0 for the Maven coordinates.

Cheers,
Thorben

Cool Thanks

Does the python script have access to the process objects? For example: ${order.price}

Getting an error “Can’t find scripting engine”

The jython 2.7.0 jar is in tomcat/lib and also in the pom.

Hi,

how did you specify the language to use. Could you attach your DMN file and the full stacktrace?

Cheers,
Sebastian

I followed the documentation here:
https://docs.camunda.org/manual/7.4/user-guide/process-engine/decisions/configuration/

Replaced “groovy” with “python”

But Im still seeing the error "Can’t find scripting engine ‘python’: scriptEngine is null

Hi,

I think I can reproduce that. Would you mind to test if you have the same issue with the jython-2.5.3.jar? I’m not sure why but 2.5.3 works for me whereas with 2.7.0 no script engine is found. I have to debug this to understand the root cause.

Cheers,
Sebastian

Hi,

sorry for the confusion I now remember that they change the site.py loading with jython 2.7.0. So there are at least 3 ways to use jython 2.7.0. :slightly_smiling:

  1. Use the jython-standalone-2.7.0.jar instead of the jython-2.7.0.jar
  2. Set the java option python.import.site=false to disable site package loading, i.e. JAVA_OPTS=-Dpython.import.site=false ./apache-tomcat-8.0.24/bin/catalina.sh run
  3. Set the JYTHONPATH to point to your local python 2.7 installation, i.e. JYTHONPATH=/usr/lib/python2.7/ ./apache-tomcat-8.0.24/bin/catalina.sh run

Does this solve the issue for you?

Cheers,
Sebastian

1 Like

Switching to jython 2.7.0 standalone fixed the issue.

Thanks.

Hi @menski! I’m not a Java dev and trying to use JavaScript or Python scripting in Camunda.

I cannot get it to work :slight_smile: and the Docs aren’t helping (prob due to my lack of Java/Wildfly knowledge).

As it says here there is the option to either:

  • use secondary scripting engine through Process Application
  • add secondary scripting engine globally

I am confused, I tried adding jython-standalone-x.jar to /lib (using WildFly) > ScriptEngine not found error
Then I added jython-standalone-x.jar to my servlet-war maven project through maven dependency > ScriptEngine not found.

Do you have a guide (steps/link) how to add a scripting engine (pref for global use) under WildFly?

Thanks a million!

Hi @Lxnd,

on Wildfly there is no global lib folder. Wildfly uses modules and has an more explicit dependency system.

So if you want to use jython you have to add a jython module to the wildfly and import it in module you want to use it. You can have a look at the modules we use for our testing environments. There we add jython 2.5 and add it as dependency to the camunda-engine module. If you want to use the dmn-engine standalone you would add it to the camunda-engine-dmn module.

Btw javascript should work out of the box as it is part of the jdk and no external dependency. Could you share your environment (camunda & jdk version), process or decision and the error you are receiving?

Cheers,
Sebastian

1 Like

Hi @menski

Thanks for those Wildfly links, got to read up on it…

Indeed the Javascript works out of the box, great!

I am using JDK 1.8.0_92 and Camunda 7.5.0_a4 (indeed bleeding edge ) on Wildfly 10

Regarding use of Jython:
Does this mean I have to re-compile camunda-engine myself with the added dependencies you mention above or can I ‘reuse’ an existing Camunda distro and run e.g. jboss-cli:

jboss-cli   (to get JBoss shell)
$ connect
$ module add --name=org.python.jython --resources=D:\Dev\jython-standalone-2.7.1b3.jar --dependencies=javax.api

(this still gives the error below btw)

An error happend while submitting the task form :
Cannot submit task form 967abd42-1dd3-11e6-b0b1-22c9d095bc69: Can’t find scripting engine for ‘jython’: scriptEngine is null

With accompanying CLI error:

17:09:01,011 ERROR [org.camunda.bpm.engine.context] (default task-11) ENGINE-16004 Exception while closing command context: Can’t find scripting engine for ‘jython’: scriptEngine is null: org.camunda.bpm.engine.exception.NullValueException: Can’t find scripting engine for ‘jython’: scriptEngine is null
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)

17:09:01,026 WARNING [ExceptionHandler] (default task-11) org.camunda.bpm.engine.rest.exception.RestException: Cannot submit task form 967abd42-1dd3-11e6-b0b1-22c9d095bc69: Can’t find scripting engine for ‘jython’: scriptEngine is null
at org.camunda.bpm.engine.rest.sub.task.impl.TaskResourceImpl.submit(TaskResourceImpl.java:120)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

Caused by: org.camunda.bpm.engine.exception.NullValueException: Can’t find scripting engine for ‘jython’: scriptEngine is null
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)

Am 99.9% sure the error is triggered by this DMN in my process flow:

decisions_1.dmn (2.0 KB)

Thanks for your advice!

Hi,

you have to add the jython dependency to the camunda wildfly module.xml you want to use it with. You don’t have to recompile it. You have to add it to the camunda-engine wildfly module.xml if you use the BPMN engine to call a decision task which will use the DMN engine. If you have an own application which uses the DMN engine by itself in standalone mode I think you have to add it to the camunda-engine-dmn wildfly module.xml. As you are using the execution variable in the script I think you use it in the Context of the BPMN engine so the former applies.

As a side note: If I remember correctly it is not possible to return something from a python script. It either hast to be an expression or you have to choose an other language I guess.

Cheers,
Sebastian

1 Like

Got it to work :tada:

For those struggling with the same: in order to use scripting engine Python/Jython (or Ruby/JRuby for that matter) on WildFly (Camunda 7.5.0_Alpha + WildFly 10) follow these steps:

  1. Download jython jar from e.g. Maven (I took jython-standalone so I didn’t have to deal with dependencies)
  2. Run start-camunda
  3. Run server\wildfly-XXXversion\bin\jboss-cli (and type connect after you are in the JBoss shell)
  4. Then run the below for jython (replace --resources with correct path)*:
module add --name=org.python.jython --resources=D:\Dev\jython-standalone-2.7.1b3.jar --dependencies=javax.api
  1. Edit server\wildfly-XXXversion\org\camunda\bpm\camunda-engine\main\module.xml and add the following below the line that contains groovy-all:
<module name="org.python.jython" services="import"/>
  1. You can close jboss-cli and you’ll have to restart your wildfly server completely, but that should do the trick!

Now since Python/Jython doesn’t return variables from scripts according to @menski, I guess I’ve got to get my JavaScript book off of the top bookshelf :expressionless:

*) for JRuby see here

NOTE: the above should work the same for JBoss (obviously) and is all thanks to @menski answering my Q’s!

2 Likes

Hi @Lxnd,

thanks for sharing this nice summary. :clap:

You could still use python to evaluate a single expression like foo > 12.

Cheers,
Sebastian