tags:

views:

600

answers:

2

Hello all,

This is a question from a JAVA noob.

I have eclipse open (JRE 1.6), I have copied this code into an eclipse class: http://bit.ly/WLntN

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

A: 

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();
}
yogman
The question wasn't about ScriptEngines in JDK1.6 but about the JSObject which allows applets to communicate with javascript on the page the applet resides in
jitter
+3  A: 

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

jitter
Genius. I just imported that jar as an external library and it worked! No complaints from eclipse. :)
Abs