Hm… those docs seem to be outdated; I thought they'll be updated with the release - hey, Hannes and Norris, what'd be the way to update them?
In the meantime, you can download Rhino 1.7R3, and open javadoc/index.html in the distribution itself, then look around the org.mozilla.javascript.commonjs.module package.
import java.net.*;
import java.util.*;
import org.mozilla.javascript.*;
import org.mozilla.javascript.commonjs.module.*;
import org.mozilla.javascript.commonjs.module.provider.*;
...
// Do this once:
List<URI> paths = Arrays.asList(
);
ModuleSourceProvider sourceProvider = new UrlModuleSourceProvider(paths, null);
ModuleScriptProvider scriptProvider = new SoftCachingModuleScriptProvider(sourceProvider);
RequireBuilder builder = new RequireBuilder();
builder.setModuleScriptProvider(scriptProvider);
// Then, for every script you want to execute you'll do something like this:
Context cx = Context.enter();
try {
Scriptable topLevelScope = cx.initStandardObjects();
Require require = builder.createRequire(cx, topLevelScope);
// Finally, if you want to execute a top-level module, do this:
require.requireMain(cx, "mainModuleId");
// Or, if you just want require() in your top level scope, but want to run
// some script manually, then just do:
require.install(topLevelScope);
Script script = getMyScriptFromSomewhere();
script.exec(cx, topLevelScope);
} finally {
Context.exit();
}
Attila.