I recently wanted to create my own copy of GregorianCalendar
to add some System.out.println
to help me understand how it works. I copied the source and renamed the class, but it wouldn't compile because the source references package-private names in other classes. So I tried adding package java.util;
to the source and putting it in a java\util
subdirectory of my working directory. I got the program to compile, but it is throwing java.lang.SecurityException: Prohibited package name: java.util
.
After reading through the tutorial on Security, I tried running policytool
to give myself permission to define a class in java.util
. I now have a file policy1
that looks like:
grant {
permission java.lang.RuntimePermission "defineClassInPackage.java.util";
};
(plus the DO NOT EDIT comment). This is in my work directory, same as my test program. I ran (in a Command Prompt window):
java -Djava.security.manager -Djava.security.policy=policy1 Test35
But it's still not working.
Exception in thread "main" java.lang.SecurityException: Prohibited package name: java.util
at java.lang.ClassLoader.preDefineClass(ClassLoader.java:659)
at java.lang.ClassLoader.defineClass(ClassLoader.java:758)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:455)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:367)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at Test35.main(Test35.java:13)
Did I do something wrong, or miss a step?