1

As the description of Wscript:String value indicating the command line used to run the script: The command line should appear exactly as it would if you typed it at the command prompt.

I can run my java file using the command "java test http://www.bbc.co.uk/news/world-us-canada-12116778" but it is not working when I wrote the JavaScript below. Can someone can tell me why? Thank you or can tell me there is some other method to call my Java file when I open a html file?

<script type="text/javascript">
funciton {}
var WshShell = new ActiveXObject("WScript.Shell");
var oExec= WshShell.Exec(""java test http://www.bbc.co.uk/news/world-us-canada-12116778"");
while (oExec.Status == 0)
{
     WScript.Sleep(100);
}
</script>
2
  • Well, running such scripts properly require to change the client's security settings. If want to run Java code maybe you should write an applet or look at Java Web Start technology? Commented Jan 5, 2011 at 20:42
  • Agree with Lukas, but if you are commited...Do you have an error message ? Also, your call implies you are calling a class called "test". That means you need a file called "test.class" somewhere in the classpath of the shell that is being invoked. And, "java.exe" also needs to be in the PATH since it is not fully qualified. I feel like eventually you will need to do something like "c:\java\bin\java.exe -jar test.jar ......." because your command line (shell) probably has some environment setup that Wscript called from the browser does not have. Commented Jan 5, 2011 at 22:24

1 Answer 1

2

Take a look at the WSHSell object's run method. The following code works for me:

var shell = new ActiveXObject("WScript.Shell");
shell.run("cmd /c java -jar MyApplication.jar");
// should work without JARs as well, take care for the working path

The run method has an option to wait for the java program to return.

Hope this helps.

Sign up to request clarification or add additional context in comments.

1 Comment

@nokul I have jar inside c://test folder, I tried as shell.run("cmd /c java -jar c:/test/MyApplication.jar");. But not working.What should I do?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.