Java JSObject:下载它还是在 JRE 1.6 中可用?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1664604/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 18:52:57  来源:igfitidea点击:

JSObject: Download it or available in JRE 1.6?

java

提问by Abs

This is a question from a Java noob.

这是一个来自 Java noob 的问题。

I have eclipse open (JRE 1.6), I have copied this code into an eclipse class.

我打开了 eclipse (JRE 1.6),我已将此代码复制到 eclipse 类中

The line in question is this:

有问题的行是这样的:

import netscape.javascript.JSObject;

Eclipse is complaining that the import can not be resolved. I read that in the docs that the Java Plug-In comes as standard and contains the above. I assumed I don't need any extra JAR files. Is this true?

Eclipse 抱怨无法解决导入问题。我在文档中读到 Java Plug-In 是标准配置并包含上述内容。我假设我不需要任何额外的 JAR 文件。这是真的?

Or do I need to download something to make use of JSObject?

或者我需要下载一些东西来使用 JSObject 吗?

Thanks all

谢谢大家

采纳答案by jitter

Search for the plugin.jarnormally located in your jre\libfolder. You will need to include that one explicitly in your eclipse project I guess

搜索plugin.jar通常位于您的jre\lib文件夹中的。我猜你需要在你的 eclipse 项目中明确包含一个

btw. don't forget to set the MAYSCRIPTattribute on your applet tag in order to explicitly enable java-js communication which normally is disabled by default for security reasons

顺便提一句。不要忘记MAYSCRIPT在小程序标签上设置属性,以便显式启用 java-js 通信,出于安全原因,该通信通常默认禁用

回答by yogman

Javascript is just one of the ScriptEngines in JDK1.6.

Javascript 只是 JDK1.6 中的 ScriptEngines 之一。

http://java.sun.com/developer/technicalArticles/J2SE/Desktop/scripting/:

http://java.sun.com/developer/technicalArticles/J2SE/Desktop/scripting/

ScriptEngineManager mgr = new ScriptEngineManager();
ScriptEngine jsEngine = mgr.getEngineByName("JavaScript");
try {
  jsEngine.eval("print('Hello, world!')");
} catch (ScriptException ex) {
  ex.printStackTrace();
}    

回答by kakeakeai

If in linux and you can not find the jar file (possibly using openjre) Simply copy it from a windows installation to your local linux distro and use it like you would any other jar file.

如果在 linux 中找不到 jar 文件(可能使用 openjre),只需将它从 Windows 安装复制到本地 linux 发行版,然后像使用任何其他 jar 文件一样使用它。