0

I've got an applet, which has to exec a program on the same server.

Runtime c = Runtime.getRuntime();
window.finishedQuery("Got Runtime...");
Process p = c.exec(String.format("cmd");
window.finishedQuery("Excecuted CMD");

2nd line doesn't work in the browser, but in the Netbeans applet viewer it does.

window is my applet, and it does show got runtime but not excecuted CMD.

In Google chrome I see the following message:

access denied ("java.io.FilePermission" "<<ALL FILES>>" "execute")

I guess the applet "thinks" that I want to get access to the users PC/programs, but I want to start a program on the server.

What do I have to do?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • 1
    Could you elaborate on "does not work"? How do you know? What do you expect to see, and what actually happens? – GargantuChet Nov 21 '12 at 21:52
  • well, window is my applet, and it does show "got runtime" but not "excecuted CMD", i dont know how to show more details...i guess the applet "thinks" that i want to get access to the users PC/programms, but i want to start a programm on the server :S – user1843351 Nov 21 '12 at 21:58
  • okay, in google chrome i see the following message "access denied ("java.io.FilePermission" "<>" "execute")" – user1843351 Nov 21 '12 at 22:06

2 Answers2

2

If created by the applet, the Process will be created in the JVM of the client machine. That VM will not be able to call methods on the server.

The best way to approach this is to have the sand-boxed applet call home to a web-service (servlet, JSP, PHP, ASP..) on the same host it comes from. Have the web-service create the Process1, and provide the output to the applet for consumption/display.

1. Also, go through the Java World article linked from the runtime.exec Wiki & implement all the recommendations, but for 1.5+ use a ProcessBuilder to create the Process.

Community
  • 1
  • 1
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • To get you right: I have to write a second applet which implements the process. I call the second applet from the first applet and get the results from there? Do i have to grant any rights to one of the applets? Is there no easier way? – user1843351 Nov 22 '12 at 13:41
  • No I did not mean two applets, see the update. Have you been through the Java World article yet? Show the updated code as an edit to the question. – Andrew Thompson Nov 22 '12 at 14:17
  • Okay, thank you for your help, i found a tutorial for creating services in java, i'll try these... – user1843351 Nov 25 '12 at 17:50
0

Okay, i wrote a service to create the process and created a "client-class" via wsimport...everything works fine in netbeans applet manager, but when i start the applet in my browser, the applet doesnt request the service, even when i put my applett on a local webserver(xampp) and start the service on the same client. i thought if both are on the same client, i dont have to sign my applet? (note sure if i have to make this a new question or an answer to my question...)