Running Activiti on JDK8

… just works!

All the Activiti code is written with JDK6 compatibility in mind, so it’s no surprise it just works out of the box.

Scripting

There are however some subtle changes when you use Script Task with javascript. In JDK 8, the Rhino engine has been replaced with Nashorn (which is a very good thing!).

Our QA did show us that some of our unit tests with javascript script task did not pass on JDK 8. But don’t worry, the changes are minimal. More precise, we found two things

1. importing packages

In JDK 6/7 you can import a java package and then use classes from that package in your javascript (eg to use an arraylist):

importPackage (java.util);
var myVar = new ArrayList();

This doesn’t work on Nashorn and thus JDK 8. However, the nice developers of Nashorn have provided a way to support this in a backwards compatible way by loading a certain file:

load("nashorn:mozilla_compat.js");
importPackage (java.util);
var myVar = new ArrayList();

And everything will work again nicely.

2. Implicit variable fetching

This one is more subtle. On JDK 6/7 you could do this

var outcome = task.getVariableLocal('outcome');
if (outcome == 'approve') {
  task.setCategory('approved');
} else {
  task.setCategory('rejected');
}

However, due to an error in our unit test, we didn’t actually set the variable on local scope but on process instance scope. Still, the test worked on JDK 6/7 and failed on JDK8!

It took me some deep debugging, but finally I found the error. In JDK6/7, the getVariableLocal(‘outcome’) does resolve to null too. However, it does a fetch of getVariable(‘outcome’) immediately afterwards. This does not happen on JDK8.

There is a subtle thing going on here: on JDK6/7 something like

var outcome;

or

var outcome = null;

triggers a lookup in the ScriptingBindings, which defaults to a getVariable() call in Activiti. The script bindings call does not happen on JDK 8, which is actually more correct! So this is actually something to be aware of when using JDK6/7.

TL;DR

Activiti just works on JDK 8. If you are using javascript in your script task, be aware of subtle changes.

2 Comments

  1. bill simons August 14, 2014

    have you tried to use groovy on grails toll suite eclipse kepler or eclipse luna.
    do you have any suggestions…I believe you would use groovy complier 2.3. thanks for the info
    you can use activiti on jdk 8

  2. Joram Barrez August 14, 2014

    @Bill: sure, why would the Eclipse version matter for this? What does the Groovy compiler has to do with this?

Leave a Reply

Your email address will not be published. Required fields are marked *