Helma Logo
main list history


The helma.system module provides methods to access the Helma NG scripting engine.

Command line arguments

Command line arguments passed to the main script can be accessed through the args property of the helma.system module. This is currently an instance of an unmodifiable java.util.List, althought we may expose this as JavaScript array in the future.


One cool new feature the helma.system module provides is the createSandbox() function to create JavaScript sandboxes. It allows you to set up an isolated JavaScript environment with its own module search path and global object. Optionally, you can inject global properties, restrict access to Java objects using a ClassShutter, and seal the global object.

Repositories and Resources

FIXME: addRepository(), getRepositories()

Host Objects

By default, Helma NG does not contain any custom host objects. This makes sense when using Helma NG in other contexts than the typical web application.

You can also register your own host objects using the helma.system.addHostObject() method, passing the host object java class as only argument.

Extending Java Classes

Helma NG allows you to add methods and properties to existing Java classes.

The helma.system.extendJavaClass() takes a java class as argument and returns an extended java class wrapper. You can add Javascript functions to the java class like it was a Javascript constructor, using the class wrapper's prototype property.

  var HashMap = helma.system.extendJavaClass(java.util.HashMap);
  HashMap.prototype.dump = function() { res.write(this); }

Note that while the class wrapper works as constructor for the extended class, the added functions and properties are available also on objects created using the standard java constructor and even objects created and returned from java code. The Helma NG object wrapper takes care of this.

Note that this is different from Rhino's JavaAdapter. JavaAdapter allows you to create new java classes in javascript, extending existing classes and implementing existing interfaces. The Helma NG java class extension feature allows you to add scripted functions to existing java classes without creating a new class.

You can also script java superclasses and interfaces. However, Helma NG currently does not implement extended class merging or chaining. In other words, if both java.util.HashMap, java.util.Map and java.lang.Object classes are extended, java instances will only have the "nearest" extension: HashMap instances will only have the extended properties of java.util.HashMap, TreeMap objects those of java.util.Map, and ArrayList those of java.lang.Object.

Setting the Optimization Level

The helma.system.setRhinoOptimizationLevel() method allows you to set the Rhino optimization level. Accepted values are integer numbers between -1 and 9. The default level is 0 and implements basic Javascript to Java bytecode compilation. Level -1 disables the bytecode compiler and sets Rhino to interpreter mode, which is required for some features such as continuations. Levels 1 to 9 add some optimizations that may or may not be detrimental to your health.

Note that Helma NG can run in both Java-compiled and interpreted mode in the same application, so you can call this on a per-request basis in the onInvoke callback. Also note that setting the optimization level in the 0..9 range does not cause scripts that have already been compiled and cached to be recompiled.

Going further

The system module provides utility methods getRhinoContext() and getRhinoEngine() to access the current Rhino Context and Rhino Engine instances. These classes provide a lot of Javascript related functionality that can be easily used from application code.

Links to this page: Release 0.2