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

前端 未结 4 1404
后悔当初
后悔当初 2021-01-06 06:37

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

相关标签:
4条回答
  • 2021-01-06 07:16

    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+"];");
    }
    
    0 讨论(0)
  • 2021-01-06 07:25

    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

    0 讨论(0)
  • 2021-01-06 07:29

    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.

    0 讨论(0)
  • 2021-01-06 07:31

    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

    0 讨论(0)
提交回复
热议问题