Comparison and Usage of Javascript Engines in Camunda
In this article, let’s look at how to use Javascript as a scripting language in Camunda with the introduction of Java 15.
Join the DZone community and get the full member experience.
Join For FreeIn this article, let’s look at how to use Javascript as a scripting language in Camunda with the introduction of Java 15, where the Nashorn Javascript Engine is removed from Java.
Pre-requisite
- Java 15+
- Eclipse IDE – Used in this article to switch between Java versions from demonstration
- Camunda 7.16
Background
Java 8 introduced Nashorn Javascript Engine, and Camunda is using the same to process scripts written in Javascript. With the introduction of Java 15 (supported by Camunda v7.16+), Nashorn Javascript Engine is removed. Camunda v7.16+ now supports GraalVM Javascript as a Javascript engine as well.
Further, Let’s see how to use Javascript in Camunda v7.16+ (where GraalVM Javascript support is present) with Java 15+ (without Nashorn) and prior to Java 15 (with Nashorn).
Let’s Begin
This article will use the embedded Camunda engine; if you have not done it before, follow the link to have an embedded Camunda engine application. Change the Camunda and Java versions to 7.16 and Java 8, respectively, to begin with.
Change the process.bpmn to have script task and script format as JavaScript as below.
Next, the same BPMN will run with Java 8 and Java 15. Let’s set the eclipse compiler to Java 8.
Java Script with Java version prior to 15 (in this case: Java 8):
Change the eclipse compiler to Java 8.
Next, build the project and run it. Login to the cockpit and try to start the process deployed with the script task created earlier. An error will start appearing like below.
To resolve this, we need to add the below property in application.yaml.
camunda:
bpm:
generic-properties:
properties:
scriptEngineNameJavaScript: nashorn
This is how we can run the process having script format as Javascript in Camunda 7.16+ with Java 14 and below.
Next, will see how to run the same process model if using Java 15 and above.
Java Script with Java version 15 and above (in this case: Java 17):
Change the eclipse compiler settings again to Java 17 (or any version >= 15).
Remove the below-added property from the application.yaml as it's not relevant now (Nashorn Javascript engine is not present in Java 15+).
camunda:
bpm:
generic-properties:
properties:
scriptEngineNameJavaScript: nashorn
Build and run the application and start the process using the cockpit. Again, the below error will start appearing as Camunda is unable to find the Javascript engine.
To resolve this, need to add the below 2 dependencies’ in pom.xml as Camunda 7.16 supports GraalVM Javascript as a Javascript engine.
<!-- GraalVM JavaScript Engine -->
<dependency>
<groupId>org.graalvm.js</groupId>
<artifactId>js</artifactId>
<version>21.3.3</version>
</dependency>
<!-- GraalVM JavaScript ScriptEngine -->
<dependency>
<groupId>org.graalvm.js</groupId>
<artifactId>js-scriptengine</artifactId>
<version>21.3.3</version>
</dependency>
Build and run the application and start the process using the cockpit. And it runs successfully this time.
The point to note here is both GraalVM dependencies must have the same version.
Hope this helps.
Opinions expressed by DZone contributors are their own.
Comments