-2

I want to execute my jar file on click of button from JSP. Jar file is saved on local machine.

Here is my code:-

<a href="#"
onClick="Runtime.getRuntime().exec("java -jar C:/Users/XXX/Desktop/XXX.jar");">Click Here</a>

Above code is not working for me

I also tried below code but it is also not working.

<a href="#"
onClick="window.open('file:///C:/Users/XXX/Desktop/XXX.jar')">Click Here</a>

Suggestion ?

Naseem
  • 911
  • 5
  • 18
  • 48
  • 1
    Are you serious? You can't call a JAR file from a browser, first you need to know that this jar file must be in the client machine, second all browser doesn't allow this because it's a security issue, can you explain more what you are trying to do so I can maybe suggest you another approach – Anas EL KORCHI Aug 03 '16 at 15:53
  • You may want to make the file downloadable on the client's machine from the server. Refer - http://stackoverflow.com/questions/3749231/download-file-using-javascript-jquery – Harshul Pandav Aug 03 '16 at 15:58
  • Thanks. This site will be access by local user and jar file will be available in client machine. I have created a jframe and want to launch this JFrame when user clicks on the button from JSP page. I converted the JFrame code to jar file thinking that it would be easy to call jar file from JSP page. Any other approach you would like to suggest for this ? – Naseem Aug 03 '16 at 15:58

2 Answers2

0

You can't run a .jar file in web this way. To run the .jar file you can use <applet> tag

<applet code=TicTacToe.class 
        archive="TicTacToe.jar"
        width="120" height="120">
</applet>

In your jsp file

<applet id="app"></applet>

in onclick you have to execute a javascript function

<a href="#" onClick="runJar();">Click Here</a>

In javascript function runJar()

function runJar(){
 var app=document.getElementById("app");
 app.setAttribute("code", "TicTacToe.class");
 app.setAttribute("archive", "TicTacToe.jar");
 app.setAttribute("width", "120");
 app.setAttribute("height", "120");
}
Md. Nasir Uddin Bhuiyan
  • 1,598
  • 1
  • 14
  • 24
0

It's not possible to run Java bytecode (jar) directly inside HTML page (that's you write with your JSP).

Reminder : Javascript is not Java.

It's not advised because deprecated but if you really really want to run Java code in your browser you can use a Java Applet.

Pierre C
  • 65
  • 6