4

I want to execute a jar file with using policy file from my project. my policy file is:

*grant codeBase "file:///D:/xx/yy/zz/-"{
  permission java.io.FilePermission 
    "D:/aa/bb/test.jar", "read, write, delete, execute";
};*

my project is under D:/xx/yy/zz/ folder and i want to execute test.jar in this project but i had an error:

access denied (java.io.FilePermission <> execute)

if i change policy file like this, that is ok:

*grant codeBase "file:///D:/xx/yy/zz/-"{
  permission java.io.FilePermission 
    "<<ALL FILES>>", "read, write, delete, execute";
};*

But i do not want to give all permission to my project.

And also in project i set policy file like this:

String path="D:\aa\bb\test.jar";

     System.setProperty("java.security.policy","C:\\policy\\"+"test.policy");

     System.setSecurityManager(new SecurityManager());  

Is there any body to say something about this situation ? Thanks...

Ravindra Gullapalli
  • 9,049
  • 3
  • 48
  • 70
mst
  • 466
  • 5
  • 17

2 Answers2

1

I think this "D:/aa/bb/test.jar" should be "D:\\aa\\bb\\test.jar"

Check here for more info http://docs.oracle.com/javase/7/docs/technotes/guides/security/PolicyFiles.html

docDevil
  • 72
  • 4
0

It'looks a way more like a file system security problem than a java security exception, are you using windows or linux?
What kind of file system are you using ? ext2/3/4 or NFTS or fat32 ?
And most important, are you running your program with admin right, which might be necessary to grant execute permission on some files.

Kiwy
  • 340
  • 2
  • 10
  • 43
  • my questions changed a little bit: i realize that it is about java command. my code is: ProcessBuilder pb = new ProcessBuilder(cmdList); process = pb.start(); cmdList is like "java", "-jar", path In start function, there is an security manager control with checkexec(). The exception is thrown from there. – mst Feb 14 '12 at 09:53