Java.lang.RuntimePermission when launching an applet from a web application

I am trying to read varvible envrionment from an applet, here is my code

String env = System.getenv("TWS"); System.out.println(env); Runtime rt = Runtime.getRuntime(); String s = env + "\\WebStart.bat " ; System.out.println(s); try { Process p = rt.exec(s); } catch (Exception e) { } 

when I run the code from netbeans by right-clicking and running it, it works without problems.

but when I put it in a jar file, add it to my web application and try running it from the html page using the following code

 <applet code="draw.class" archive='AppletTest.jar'> <param name="shape" value="triangle"/> </applet> 

I get an access denied error message , java.lang.RuntimePermission

I am running this web application using tomcat 6.

I read several tutorials and added the following entry to catalina.policy in tomcat 6 and restarted tomcat

 permission java.lang.RuntimePermission "accessDeclaredMembers"; 

but still the same warning. can anyone suggest a solution to this problem?

- rangana

+4
source share
1 answer

When you launch an applet from netbeans, Java virtual machines launch it under a different security mode than when launched through a browser.

Applets downloaded through browsers that are not signed using a security certificate are considered unreliable and are called unsigned applets. When working on a client, unsigned applets work in an isolated security software environment that provides only a set of safe operations. You can check whether you are invited or not using the SecurityManager . For example, in your case:

 System.getSecurityManager().checkPermission(new RuntimePermission("accessDeclaredMembers")); 

You can learn more about applet security here and here . A very good tutorial on creating signed applets can be found here .

+3
source

All Articles