无法在NetBeans中导入sun.org.mozilla.javascript.internal

The*_*eLQ 4 java netbeans importerror

在我的java程序中,我大量使用了Rhino脚本引擎的Suns implmentation.然而,最近,我的JDK在编译时似乎不再自动导入rt.jar文件.

奇怪的是,NetBeans报告了0个实时错误,它们仅在执行完整的清理和构建时出现.在我导入NativeArray之前没有发生这种情况,所以我真的很困惑为什么它突然停止工作.

眼镜:

  • 操作系统 - Windows
  • Java版本 - java版"1.6.0_20"
  • Javac版本 - javac 1.6.0_20
  • NetBeans版本 - 6.9

检查它是否存在:

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();
}

好吧它存在,所以这里是一些测试代码:

package testapp;

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

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

Netbeans输出:

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中测试,看看问题是否仍然存在.

在你说之前:不,我不是分开下载rhino,不,我不是在改变IDE,

Boz*_*zho 6

有两种迹象表明你不应该使用这个类:sun并且internal- 这意味着这是一些不应被第三方使用的内部类.因为它可以在将来的版本中更改或删除 - 即这不是API的一部分.所以 - 单独下载Rhino.

如果您使用脚本API - 仅使用API​​类/接口 - 即 javax.script