Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

running an external program from servlet

 
Andras Nemeth
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,

I tried to execute an external program (notepad.exe) via web page.

I use the following code:
String[] command = {"C:\\notepad1.exe"};
Runtime.getRuntime().exec(command);

I got the following error message:

java.security.AccessControlException: access denied (java.io.FilePermission C:\notepad1.exe execute)

Is there anyone can help me to find out what is wrong?

I checked the file:C:\j2sdk1.4.2_04\AppServer\domains\domain1\config\server.policy. It begins with:

/* AUTOMATICALLY GENERATED ON Tue Jun 22 09:46:10 CEST 2004*/
/* DO NOT EDIT */

So what is the proper way to give permission for the servlet?

Thanks in advance:
Andras
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should read the "security" portion of the Java tutorial. It will explain everything for you.
 
Andras Nemeth
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now I know the answer.


The java.policy lokks like this:


/* AUTOMATICALLY GENERATED ON Mon Jun 28 14:16:12 CEST 2004*/
/* DO NOT EDIT */

grant {
permission javax.security.jacc.WebResourcePermission "/";
permission javax.security.jacc.WebUserDataPermission "/";
permission java.io.FilePermission "<<ALL FILES>>", "execute";
permission java.io.FilePermission "c:\\1\\file.txt", "read, write, delete, execute";
};


And I had to put this file in WAR archive.

Now it works :-))
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic