This Java 6 code uses the URLClassLoader class to load and invoke a selection of engines at runtime:
Note that the
ClassLoader used to load the engine is
set as the context
ClassLoader around any calls to the
engine. Failure to do this may result in errors.
Hello, ECMAScript! Hello, Groovy! Hello, JRuby! Hello, Jython!
As well as the libraries for the scripting languages, some of the implementations require a third-party scripting engine from scripting.dev.java.net. Later versions may include support by default, in which case the external library can be dropped from the classpath.
|Language||Version||Engine Name||Requires External Engine|
|Groovy||Groovy Version: 1.6.0||groovy||no|
|JRuby||jruby 1.2.0 (ruby 1.8.6 patchlevel 287) (2009-03-16 rev 9419)||jruby||yes|
Run on a Windows PC, the code uses the following environment variables set to the library installation directories:
GROOVY_HOME=C:\Java\groovy-1.6.0 JRUBY_HOME=C:\Java\jruby-1.2.0 JYTHON_HOME=C:\Java\jython2.2.1 SCRIPT_ENGINES=C:\Java\jsr223-engines