如何在插件中显示jdk.nashorn.api.scripting.JSObject [英] How to make jdk.nashorn.api.scripting.JSObject visible in plugin

查看:1815
本文介绍了如何在插件中显示jdk.nashorn.api.scripting.JSObject的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个与Java脚本交互的Eclipse RCP。现在使用Java 8,使用nashorn,并且必须将依赖于org.mozilla.javascript(插件org.mozilla.javascript_1.7.2.v201005080400.jar)的代码更改为使用jdk.nashorn.api.scripting。

I have an Eclipse RCP that interacts with java script. Now with Java 8, nashorn is used and code that depended on org.mozilla.javascript (plug-in org.mozilla.javascript_1.7.2.v201005080400.jar) must be changed to use jdk.nashorn.api.scripting.

但是当我尝试在Eclipse中使用这个导入时,它没有看到它

But when i try to use this import in Eclipse, it does not see it

import jdk.nashorn.api.scripting.JSObject;

我收到错误:


访问限制:类型'JSObject'不是API(对所需库的限制'< ...> \ jre \lib \\\\\\\\\\\\\\\ b $ b

Access restriction: The type 'JSObject' is not API (restriction on required library '<...>\jre\lib\ext\nashorn.jar')

如何在编译时使它在类路径中可见?

How can I make it visible in the classpath at compile time?

推荐答案

jdk.nashorn.scripting是Nashorn公开的API的一部分。请参阅 https:/ /docs.oracle.com/javase/8/docs/jdk/api/nashorn/jdk/nashorn/api/scripting/JSObject.html

jdk.nashorn.scripting is part of Nashorn's exposed API. Please see https://docs.oracle.com/javase/8/docs/jdk/api/nashorn/jdk/nashorn/api/scripting/JSObject.html

它似乎某些Eclipse特定问题。我用Netbeans 8.0.2编译和编译运行以下应用程序,它按预期编译并运行:

It appears to some Eclipse specific issue. I used Netbeans 8.0.2 to compile & run the following application and it compiled and ran as expected:

package javaapplication2;

import javax.script.*;
import jdk.nashorn.api.scripting.*;

public class JavaApplication2 {
    public static void main(String[] args) throws ScriptException {
        ScriptEngineManager m = new ScriptEngineManager();
        ScriptEngine e = m.getEngineByName("nashorn");
        ScriptObjectMirror sobj = (ScriptObjectMirror)e.eval("({ foo: 33 })");
        System.out.println(sobj.getMember("foo"));
    }
}

这篇关于如何在插件中显示jdk.nashorn.api.scripting.JSObject的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆