Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

problem importing classes in JavaScript

807603Jun 26 2007 — edited Feb 8 2008
Hi,
I am using the built in rhino engine in Java 6 to execute a javascript file within my program. I am using some java classes inside the javascript, and the importClass declarations seem to be causing some problems. I have my import declarations laid out like:
importClass(x.y.foo.ClassName);
importClass(x.y.foo.ClassName2);
and the majority of the time these classes are loaded without problem. Sometimes however the class fails to load, and an exception like this is thrown:
 Problem loading script: myRhinoScript.js
javax.script.ScriptException: sun.org.mozilla.javascript.internal.EvaluatorException: Function importClass must be called with a class; had "[JavaPackage x.y.foo.ClassName]" instead. (<Unknown source>#1) in <Unknown source> at line number 1
Apparently this is because rhino can't find that class and is instead interpreting the string as a package. Therefore an attempt to call "importClass" with a package, throws the above error.

How can I make sure that this rhino script can always find my classes?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 7 2008
Added on Jun 26 2007
13 comments
1,440 views