I have a java class that I am importing unfortunately named java.net_y. My code compiles, but when I try to run it I get:
Exception in thread "main" java.lang.Security开发者_开发知识库Exception: Prohibited package name: java.net_y
I've read other threads about trying to override core java classes like java.io.....thats not what I am doing....this external class I have is just named badly.
Another thread mentioned reflection...not sure if that is required.
What can I do?
What can I do?
Rename that class.
If the class was generated from a web service WSDL, the best thing would be to regenerate it and forcing the package name to something else. Most WSDL-to-java tools have parameters to let you do that.
What you can do is to use Java Decompiler to reverse engineer what you are importing, make the necessary changes and then recompile.
I am actually assuming that you are trying to import some sort of .jar file or something along those lines. If you are importing just one class, then all you need to do is to rename it.
I should rename your class. You cannot put classes to java package. See
java.lang.ClassLoader#predefineClass()
This is a private method that performs the following check:
if ((name != null) && name.startsWith("java.")) {
throw new SecurityException("Prohibited package name: " +
name.substring(0, name.lastIndexOf('.')));
}
As far as I understand this is exactly the exception you see.
Sometimes people have to override classes from JDK. It is not your case, but I'd like to mention it just in case. To do this you have to put this overridden class to
-Xbootclasspath
instead of regular
-classpath
when you are running your JVM
精彩评论