1

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" 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.

Gruber
  • 531
  • 1
  • 6
  • 17

2 Answers2

1

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.

rahulmohan
  • 1,285
  • 11
  • 19
0

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.

Nishan
  • 2,821
  • 4
  • 27
  • 36
  • ehm, i don't really understand your post. If all objects that are available to JScript in a browser are also available to JScript in a JVM, why is that the reasen, my program isn't running like i want to? – Gruber Mar 10 '11 at 10:21
  • @Gruber Sorry, left out a 't' in 'Not'. What I mean to say is 'ActiveXObject' is instantiated by browser and provided to javascript runtime to use. When you are running javascript inside JVM there is no browser to create this object for you. – Nishan Mar 10 '11 at 10:54