Support > Repository > Business logic > Points to note when using Java 6/7

In Java 6/7 there are some different scripting rules.

Java ships with the following server side JavaScript engine.

Java versionEnclosed JavaScript engine
Java 8Nashorn
Java 6/7Rhino

All the code exemplified in this document is based on how to write in Java 8 (Nashorn).This page explains the changes when operating in Java 6/7 (Rhino).

Please be careful.The operating environment of Wagby R8 is Java 8 or higher.Therefore, when upgrading to Wagby R8, you need to rewrite Rhino based scripts.

Java 8 (Nashorn)

Use the variable stdout.

stdout.println("Hello from Nashorn.");

Java 6/7 (Rhino)

In Rhino you can use println directly.

println("Hello from Rhino.");

Java arrays are implemented using java.lang.reflect.Array.newInstance.

The following example creates a character array in a script.

var obj = java.lang.reflect.Array.newInstance(java.lang.String, 1);
obj[0] = "テストです。";
p.errors.addJfcerror(errorManager.getJfcerror("error.original", obj, p.locale));

When using Java classes in scripts, Java.type can be used when using Java 8 environment.

var Foo = Java.type("jp.jasminesoft.wagby.Foo");
var foo = new Foo;

When using Java 6/7, use importClass.At this time, it is necessary to declare function process at the same time.

importClass(Packages.jp.jasminesoft.util.ExcelFunction);
importClass(Packages.jp.jasminesoft.jfc.error.Jfcerror);
importClass(Packages.jp.jasminesoft.jfc.error.Jfcwarn);
importClass(Packages.jp.jasminesoft.jfc.error.Jfcinfo);

importClass(Packages.jp.jasminesoft.wagby.Foo); /* 追加した */

function process() {

...ここに開発者独自のコードを記述する。

}

In other words, in the Java 8 environment, you can skip the function definition called function process (), but in Java 6/7 you need to define the function at the time you use the importClass declaration.

In that case, it is a good idea to add the classes (ExcelFunction and Jfcerror) frequently used in the code at the same time to the declaration as shown above.