aspose file tools*
The moose likes Servlets and the fly likes running an external program from servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "running an external program from servlet" Watch "running an external program from servlet" New topic
Author

running an external program from servlet

Andras Nemeth
Greenhorn

Joined: Jun 22, 2004
Posts: 2
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

Joined: May 29, 2003
Posts: 1258
You should read the "security" portion of the Java tutorial. It will explain everything for you.


Nathaniel Stodard<br />SCJP, SCJD, SCWCD, SCBCD, SCDJWS, ICAD, ICSD, ICED
Andras Nemeth
Greenhorn

Joined: Jun 22, 2004
Posts: 2
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 :-))
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: running an external program from servlet