Unable to import sun.org.mozilla.javascript.internal into NetBeans

In my java program, I make heavy use of the Sun implementation for the Rhino script. More recently, however, the JDK does not seem to automatically import the rt.jar file at compile time.

It is strange that NetBeans reports 0 live errors, they appear only when performing a complete cleaning and assembly. This did not happen before when I imported NativeArray, so I'm really confused about why it suddenly stopped working.

Specifications:

  • OS - Windows
  • Java Version - Java Version 1.6.0_20
  • Javac version - javac 1.6.0_20
  • NetBeans Version - 6.9

Check if it exists:

C: \ Documents and Settings \ LordQuackstar \ Desktop \ TestApp \ src> javap sun.org.mozill
a.javascript.internal.WrappedException
Compiled from "WrappedException.java"
public class sun.org.mozilla.javascript.internal.WrappedException extends sun.or
g.mozilla.javascript.internal.EvaluatorException {
    static final long serialVersionUID;
    public sun.org.mozilla.javascript.internal.WrappedException (java.lang.Throwa
ble);
    public java.lang.Throwable getWrappedException ();
    public java.lang.Object unwrap ();
}

Well, it exists, so here are some test codes:

package testapp;

import sun.org.mozilla.javascript.internal.WrappedException;

public class Main {
    public static void main(String[] args) {
        WrappedException e = new WrappedException(null);
    }
}

NetBeans Output:

init:
deps-clean:
Updating property file: C: \ Documents and Settings \ LordQuackstar \ Desktop \ TestApp \ build \ built-clean.properties
Deleting directory C: \ Documents and Settings \ LordQuackstar \ Desktop \ TestApp \ build
clean:
init:
deps-jar:
Created dir: C: \ Documents and Settings \ LordQuackstar \ Desktop \ TestApp \ build
Updating property file: C: \ Documents and Settings \ LordQuackstar \ Desktop \ TestApp \ build \ built-jar.properties
Created dir: C:\Documents and Settings\LordQuackstar\Desktop\TestApp\build\classes
Created dir: C:\Documents and Settings\LordQuackstar\Desktop\TestApp\build\empty
Compiling 1 source file to C:\Documents and Settings\LordQuackstar\Desktop\TestApp\build\classes
C:\Documents and Settings\LordQuackstar\Desktop\TestApp\src\testapp\Main.java:8: package sun.org.mozilla.javascript.internal does not exist
import sun.org.mozilla.javascript.internal.WrappedException;
C:\Documents and Settings\LordQuackstar\Desktop\TestApp\src\testapp\Main.java:16: cannot find symbol
symbol  : class WrappedException
location: class testapp.Main
                WrappedException e = new WrappedException(null);
                ^
C:\Documents and Settings\LordQuackstar\Desktop\TestApp\src\testapp\Main.java:16: cannot find symbol
symbol  : class WrappedException
location: class testapp.Main
                WrappedException e = new WrappedException(null);
                                         ^
3 errors
C:\Documents and Settings\LordQuackstar\Desktop\TestApp\nbproject\build-impl.xml:528: The following error occurred while executing this line:
C:\Documents and Settings\LordQuackstar\Desktop\TestApp\nbproject\build-impl.xml:261: Compile failed; see the compiler error output for details.
BUILD FAILED (total time: 0 seconds)

:

C:\Documents and Settings\LordQuackstar\Desktop\TestApp\src\testapp>javac Main.java
Main.java:3: package sun.org.mozilla.javascript.internal does not exist
import sun.org.mozilla.javascript.internal.WrappedException;
                                          ^
Main.java:7: cannot find symbol
symbol  : class WrappedException
location: class testapp.Main
        WrappedException e = new WrappedException(null);
        ^
Main.java:7: cannot find symbol
symbol  : class WrappedException
location: class testapp.Main
        WrappedException e = new WrappedException(null);
                                 ^
3 errors

, ? . , . .

Linux, , .

: , , , IDE,

+3
4

, : sun internal - , , . - .. API. - Rhino .

API - API/ - javax.script

+6

, .

: JavaScript sun.org.mozilla.javascript.internal.NativeArray?

, . Java, vars, JavaScript, 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+"];");
}
+4

. rt.jar JRE . .

+1

This is an old question, however, when I had this problem, my solution was to do more work in the JavaScript environment and then return a primitive type (String / Boolean), not an object.

Of course, this will not satisfy all and all requirements, but in some cases it may help.

0
source

Source: https://habr.com/ru/post/1753074/


All Articles