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

发布于 2024-09-08 11:38:28 字数 3723 浏览 5 评论 0原文

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

奇怪的是,NetBeans 报告 0 个实时错误,它们仅在执行完整的 Clean & 操作时才会出现。建造。之前我导入 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);
    }
}

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

那么什么会导致这个突然失败呢?昨天还运行得很好。除了从同一个包中导入另外 2 个类之外,我没有做任何更改。我的依赖关系都没有改变。

将在linux下进行测试,看看问题是否仍然存在。

在你说之前:不,我不会单独下载 rhino,不,我不会改变 IDE,

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 anymore when compiling.

Whats strange is that NetBeans reports 0 live errors, they only show up when doing a complete Clean & Build. This wasn't happening before when I was importing NativeArray, so I'm really confused on why it all of a sudden stopped working.

Specs:

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

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

Ok it exists, so here's some test code:

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)

Command line output:

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

So what would cause this to fail all of a sudden? It was working just fine yesterday. I didn't change anything besides importing 2 more classes from the same package. None of my dependencies changed.

Will test in linux to see if the problem still exists.

Before you say it: No I'm not download rhino separatly, No I'm not changing IDEs,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

不即不离 2024-09-15 11:38:28

有两个迹象表明您不应该使用此类:suninternal - 这意味着这是一些第三方不应使用的内部类。因为它可以在未来的版本中更改或删除 - 即这不是 API 的一部分。所以 - 单独下载 Rhino。

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

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

浮云落日 2024-09-15 11:38:28

我同意上述建议,您最好不要尝试使用 sun 内部软件包。

这就引出了一个问题,如何在没有 sun.org.mozilla.javascript.internal.NativeArray 的情况下访问 JavaScript 数组?

对我有用的是代码如下。这将基于名为 vars 的 JavaScript 数组创建一个名为 vars 的 Java 数组。

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

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+"];");
}
挽手叙旧 2024-09-15 11:38:28

我有同样的错误。您必须手动将 JRE 目录中的 rt.jar 添加到项目库中。只有这个解决方案似乎有效。您还可以在此处查看有关此方法的教程罗布·迪·马科 (Rob Di Marco)

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

放低过去 2024-09-15 11:38:28

现在这是一个老问题了,但是当我遇到这个问题时,我的解决方案是在 JavaScript 环境中做更多工作,然后返回原始类型(String / Boolean)而不是对象。

当然,这并不能满足所有人和所有要求,但在某些情况下可能会有所帮助。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文