In my java program I make heavy use of Suns implmentation of the Rhino script engine. Very recently however, my JDK does not seem to automatically import the rt.jar file any
I agree w/ the above advice that you're better off not trying to use the sun internal packages.
This begs the question, how do you access JavaScript arrays w/out sun.org.mozilla.javascript.internal.NativeArray?
What worked for me is code as follows. This creates a Java array called vars based off a JavaScript array called vars.
int varsLength = ((Double)engine.eval("vars.length;")).intValue();
Object[] vars = new Object[varsLength];
for(int i=0; i<vars.length; i++){
vars[i] = engine.eval("vars["+i+"];");
}
There are two indications that you shouldn't use this class: sun
and internal
- these mean that this is some internal class that shouldn't be used by third parties. Because it can change or be removed in future releases - i.e. this is not part of an API. So - download Rhino separately.
If you are using the scripting API - use only the API classes/interfaces - i.e. javax.script
This is an old question now, however when I had this problem, my solution was to do more work in the JavaScript environment and then to return a primitive type (String / Boolean) rather than an object.
Of course, this will not satisfy everyone and all requirements, but it may help in some cases.
I had the same error. You must manually add rt.jar
from JRE dir to project libraries. Only this solution seems work. You can also see a tutorial on this approach here by Rob Di Marco