This is a questio开发者_如何学运维n from a Java noob.
I have eclipse open (JRE 1.6), I have copied this code into an eclipse class.
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?
Or do I need to download something to make use of JSObject?
Thanks all
Search for the plugin.jar
normally located in your jre\lib
folder. You will need to include that one explicitly in your eclipse project I guess
btw. don't forget to set the MAYSCRIPT
attribute on your applet tag in order to explicitly enable java-js communication which normally is disabled by default for security reasons
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.
Javascript is just one of the ScriptEngines in JDK1.6.
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();
}
精彩评论