you could get an answer simply by searching for "importPackage" is not defined ... :-)
To use importPackage your root scope must be created with new ImporterTopLevel(cx). HTH Merten -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of tlrobinson Sent: Monday, January 21, 2008 11:24 AM To: [email protected] Subject: Re: Problem with importPackage On Jan 19, 4:55 pm, Norris Boyd <[EMAIL PROTECTED]> wrote: > On Jan 19, 4:47 pm, tlrobinson <[EMAIL PROTECTED]> wrote: > > > > > On Jan 19, 12:40 pm, Norris Boyd <[EMAIL PROTECTED]> wrote: > > > > On Jan 19, 7:00 am, tlrobinson <[EMAIL PROTECTED]> wrote: > > > > I too am wondering how to use external libraries with Rhino. > > > > I've tried putting the .jar in my classpath and using the > > > > java.com.domain.packagename syntax, but no such luck. > > > > > Thank you. > > > > If you have a class com.foo.Bar, then you load it by > > > "Packages.com.foo.Bar". "java.com.foo.Bar" would only work if your > > > class was really a subpackage of "java". > > > > 1.7 will include a top-level definition for "com", among others. > > > Once > > > 1.7 is released you'll be able to load com.foo.Bar using com.foo.Bar. > > > > --N > > > I'm trying to use Xerces: > > > js> var doc = new Packages.org.apache.xerces.dom.DocumentImpl(); > > js: "<stdin>", line 2: uncaught JavaScript runtime exception: > > TypeError: [JavaPackage org.apache.xerces.dom.DocumentImpl] is not a > > function, it is org.mozilla.javascript.NativeJavaPackage. > > > xercesImpl.jar is in my classpath, and the equivalent in Java works > > fine: > > > org.w3c.dom.Document doc = new > > org.apache.xerces.dom.DocumentImpl(); > > > Thanks for your help. > > The error you're getting indicates that Rhino can't load the class > org.apache.xerces.dom.DocumentImpl. I tried it, with success: > > [rhino] java -classpath "build/rhino1_7R1/js.jar;../../../downloads/ > xalan-j_2_7_1/xercesImpl.jar" org.mozilla.javascript.tools.shell.Main > Rhino 1.7 release 1 2008 01 19 > js> new Packages.org.apache.xerces.dom.DocumentImpl() > [#document: null] > > --N Sigh... Thanks, I tried again with your exact syntax and it works. I'm not sure what I was doing wrong. Now importPackage works from within the shell, but when I try it from within a script called by "evaluateString" I getting this: org.mozilla.javascript.EcmaError: ReferenceError: "importPackage" is not defined. (<Test.js>#1) at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java: 3350) at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java: 3340) at org.mozilla.javascript.ScriptRuntime.notFoundError(ScriptRuntime.java: 3413) at org.mozilla.javascript.ScriptRuntime.getNameFunctionAndThis(ScriptRuntime.java: 1951) at org.mozilla.javascript.optimizer.OptRuntime.callName(OptRuntime.java: 95) at org.mozilla.javascript.gen.c1._c0(<Test.js>:1) at org.mozilla.javascript.gen.c1.call(<Test.js>) at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java: 393) at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java: 2834) at org.mozilla.javascript.gen.c1.call(<Test.js>) at org.mozilla.javascript.gen.c1.exec(<Test.js>) at org.mozilla.javascript.Context.evaluateString(Context.java:1196) at Test.main(Test.java:14) Is importPackage a shell function? I was under the impression it worked everywhere. Thanks again. _______________________________________________ dev-tech-js-engine-rhino mailing list [email protected] https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino _______________________________________________ dev-tech-js-engine-rhino mailing list [email protected] https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino
