Running jar on client from browser

6

I need to run a jar file that should be on the client's pc through the web and pass some parameters to that jar, I managed to do this with exec() of php:

exec('java -jar "C:\Users\Suporte01\Documents\NetBeansProjects\Printer\dist\Printer.jar" Hello', $output);
print_r($output);

however it runs the jar on the server ...

EDIT

It would be something like I see some web applications do like logmein , which opens a remote access program directly from the browser that is installed on your computer, as can be seen below:

Is it necessary to have any service installed on the client?

    
asked by anonymous 26.02.2014 / 13:41

3 answers

6

PHP exec() executes a server-side command, since it is not a client-side language.

Running a JAR through the browser

To run a in the browser, as you wish, what I would indicate is to use a applet , as seen in that answer and call it by javascript, as in the following example:

<applet name="myapp" archive="myjar.jar" code="com.company.MyApplet"/>
<script>
   var result = myapp.foo();
</script>

Running a JAR that is on the client computer by Internet Explorer

Another possibility, after seeing what you wanted from editing the question, is to request, through , have the client run the by ActiveXObject , as can be seen here . The example to run is this:

function RunExe(){  
  var w = new ActiveXObject("WScript.Shell");
  var myJar = 'C://WindowJar.jar'; //exemplo
  w.run(myJar);//Roda o jar
  return true;
}

If you want to work on a return of the executed file, you can use the following example:

function RunExe(){  
  var w = new ActiveXObject("WScript.Shell");
  var myJar = 'C://WindowJar.jar'; //exemplo
  var ex = w.run(myJar);//Roda o jar
  var ret = "";
  //lê a saída do jar
  while (!ex.StdOut.AtEndOfStream) {
    ret += ex.StdOut.ReadLine();
  }
  //Dá um alert no retorno
  alert(ret)
  return true;
}

Running a JAR that is on the client computer using protocols

Another alternative, not indicated for security reasons, is to use URL protocol , which means to tinker with the records of the target machine. Under this example , you can achieve this goal as follows:

Create a personized protocol

[HKEY_CLASSES_ROOT\protocolname]
@="URL: descricao"
"URL Protocol"=""

[HKEY_CLASSES_ROOT\protocolname\shell]

[HKEY_CLASSES_ROOT\protocolname\shell\open]

[HKEY_CLASSES_ROOT\protocolname\shell\open\command]
@="\"C:\Path to\Jar\myJar.jar\" %1"

Using a reference tag in HTML

<a href="protocolname:parameter-value">link</a>

However, the following can be removed from the above documentation:

  

Security Alert Applications that handle URL protocols must consider how to respond to malicious data. Because handler applications can receive data from untrusted sources, the URL and other parameter values passed to the application may contain malicious data that attempts to exploit the handling application.

Free translation:

  

Security Alert Applications that handle URL protocols should consider how to respond to malicious data. Because the application handler may receive data from untrusted sources, the URL or other parameter values passed to the application may contain malicious data that tries to exploit the manipulated application.

So, if it is not strictly necessary to use another browser, I suggest using Internet Explorer with ActiveXObject , because it is simpler and less dangerous than creating a custom protocol.

    
26.02.2014 / 13:52
1

The always jar will run on the server side. What you have to do is capture the output of the execution and send it to the client side.

I think the wiser, in this case, would be to put your jar inside a web service, and this service would provide a REST API for other services to talk to it via HTTP.

    
26.02.2014 / 13:46
1

To run a JAR on the client you have a few options:

This site contains comparisons between the two methods: link .

It's all in English so I'll try to list the key differences and similarities here:

  • Both run in a "restricted" environment if the JAR is not digitally signed;
  • In order to access restricted areas, you need to describe what you are going to do, and sign the JAR;
  • An applet runs in the browser, Java web start looks like a remote application, but it is automatically downloaded from a server.

The last option would be to "give" the JAR to the client and ask it to run directly on the client, and you could access your server to upload the information you need - in this case, your JAR would have unrestricted access to what the user can see (at least without the restrictions of an applet or Java Web Start application).

    
26.02.2014 / 21:23