javascript - load/require not defined when running js on Java 7 + rhino -
i have java program creates scriptengine (rhino) , launch js file. in js file need use dom-parser (i know there other ways of parsing xml on rhino need use dom). need load sax.js, dom-parser.js, dom.js in js (like xmldom guys suggest). turns out rhino version being used in java 7 not full version , doesn't support load or require. tried solution suggested here load/require still doesn't work.
i tried evaluating script in right order causes bug in xmldom described here.
here current java program:
public void execute() throws mojoexecutionexception, mojofailureexception { reader saxscript = new inputstreamreader(xmltojsonconvertor.class.getclassloader().getresourceasstream("sax.js")); reader domscript = new inputstreamreader(xmltojsonconvertor.class.getclassloader().getresourceasstream("dom.js")); reader domparserscript = new inputstreamreader(xmltojsonconvertor.class.getclassloader().getresourceasstream("dom-parser.js")); reader rhinoscript = new inputstreamreader(xmltojsonconvertor.class.getclassloader().getresourceasstream("rhinoconvertor.js")); try { if (!inputxmlfile.exists()) { this.getlog().info(inputxmlfile.getname() + " doesn't exists"); } context cx = context.enter(); scriptable scope = cx.initstandardobjects(); scope.put("xmlinput", scope, ioutil.tostring(new fileinputstream(inputxmlfile), "utf-8")); final require require= new require(cx, scope, new modulescriptprovider(), null, null, true) cx.evaluatereader(scope, saxscript, "sax.js", 0, null); cx.evaluatereader(scope, domparserscript, "dom-parser.js", 0, null); cx.evaluatereader(scope, domscript, "dom.js", 0, null); string jsonresult = (string) cx.evaluatereader(scope, rhinoscript, "rhinoconvertor.js", 0, null); context.exit();
so how js use dom , run on rhino?
Comments
Post a Comment