Helma Logo
main list history
previous version  overview  next version

Version 1 by hannes on 14. October 2005, 13:21

Helma 2 can be used as a library to instantly add scripting capability to any Java program. Scripts loaded from .js files can extend any Java class and implement any Java interface just using this.__extends__ = javaClassName and this.__implements__ = [javaInterfaceName, ...], respectively.

==== A trivial example

The Java side:

import org.helma.javascript.RhinoLoader;
import java.io.File;
import java.io.IOException;

public class Test {

    public static void main(String[] args)
            throws IOException, ClassNotFoundException {
        RhinoLoader loader = new RhinoLoader(new File("scriptdir"));
        Runnable test = (Runnable) loader.getInstance("Test");
        new Thread(test).start();

This tries to load a script from a file called scriptdir/Test.js that implements java.lang.Runnable. The scirpt might look like this:

this.__implements__ = "java.lang.Runnable";

function run() {