How to start a program via JavaScript from within a Java Application?
i have a little problem with starting a JavaScript (-file) from within a Java Application. I know the Application is startable through a simple Script if i put it into a sample.js. The actual call is as follows:
new ActiveXObject("MyApp.Application");
As said, the start via double click on the script file is no problem, but if i try it through the javax.script package:
// create a script engine manager
ScriptEngineManager factory = new ScriptEngineManager();
// create a JavaScript engine
ScriptEngine engine = factory.getEngineByName("JavaScript");
// evaluate JavaScript code from String
engine.eval("new ActiveXObject(\"MyApp.Application\");");
if get the following exception:
Exception in thread "main" javax.script.ScriptException: sun.org.mozilla.javascript.internal.EcmaError: ReferenceError: "ActiveXObject开发者_StackOverflow中文版" is not defined. (<Unknown source>#1) in <Unknown source> at line number 1
at com.sun.script.javascript.RhinoScriptEngine.eval(RhinoScriptEngine.java:110)
at com.sun.script.javascript.RhinoScriptEngine.eval(RhinoScriptEngine.java:124)
at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:247)
at com.ime.actia.testing.ScriptTest.main(ScriptTest.java:13)
Microsoft Windows Script is installed in the actual version. I know, ActiveX is IE specific, but i don't wanna start the App in/through the IE anyway. Has anybody an idea, how to start the program?
Thanks everyone! ^^
EDIT: Thanks for answers by now! Since I'm not able to get an ActiveXObject from within a JVM, is there another way to start an external application through JScript? I don't care, if it's an ActiveXObject.
JavaScript code in browser can use host objects supplied by the environment (i.e. the browser). ActiveXObject is one such object provided by IE. From your exception trace, it looks like that object is not available in your environment.
Not all objects which are available to Javascript running in browser will be available to Javascript running inside your Java program (JVM). And, that is why it complains 'ActiveXObject' is not defined.
精彩评论