3
grant {
     permission java.io.FilePermission "C:\\class\\*", "read, write";
     permission java.lang.RuntimePermission "createClassLoader";
};

My policy.txt

java.security.AccessControlException: access denied (java.io.FilePermission c:\class read)
    at java.security.AccessControlContext.checkPermission(Unknown Source)
    at java.security.AccessController.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkRead(Unknown Source)
    at java.io.File.isDirectory(Unknown Source)
    at java.io.File.toURI(Unknown Source)
    at loader.Main.main(Main.java:35)

My exception..???

My call

String path = "c:\\class\\";
String app = "x.MyHTMLPrint";


File file = new File(path);
URL url = file.toURI().toURL();
URL[] urls = new URL[]{url};

ClassLoader cl = new URLClassLoader(urls);
Class cls = cl.loadClass(app);

As soon as I give it full Permission it works.

any ideas? thx!

2
  • 4
    Not that familiar with the policy file, but, it would seem to me you are saying you can read anything under C:\class, but attempting to access C:\class itself. Commented Nov 24, 2009 at 23:01
  • How exactly are you calling your program? Commented Nov 24, 2009 at 23:39

1 Answer 1

8

There appears to be two problems there.

Firstly, as Yishai says, File.toURI appears to need to check that the file without the trailing separator is a directory. This is probably a bug.

Secondly, the wildcard for recursive subdirectories is '-' not '*'.

So your policy file needs to look like:

grant {
    permission java.io.FilePermission "C:\\class\\-", "read";
    permission java.io.FilePermission "C:\\class", "read";
    permission java.lang.RuntimePermission "createClassLoader";
};

Also, if you use URLClassLoader.newInstance, you don't need createClassLoader permissions, and you get a completed class loader implementation.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.