Can't import sun.org.mozilla.javascript.internal in NetBeans

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-30 22:16:41

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

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+"];");
}
kbec

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!