今天发下一个问题,自定义的包不能以java.开头 今天发下一个问题,自定义的包不能以java.开头,虽然编辑时很正常import,然后在编译的时候就找不到类了,为什么呢?要是因为它是java开头,与library里面默认的一些包有冲突,那以com.开头的包怎么不与冲突呢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Java 的 ClassLoader 人为地进行了限制,不允许开发人员自定义 java 开头的包。 01 /* Determine protection domain, and check that:02 - not define java.* class,03 - signer of this class matches signers for the rest of the classes in package.04 */05 private ProtectionDomain preDefineClass(String name, ProtectionDomain protectionDomain) {06 if (!checkName(name))07 throw new NoClassDefFoundError("IllegalName: " + name);08 09 if ((name != null) && name.startsWith("java.")) {10 throw new SecurityException("Prohibited package name: " + name.substring(0, name.lastIndexOf('.')));11 }12 if (protectionDomain == null) {13 protectionDomain = getDefaultDomain();14 }15 if (name != null)16 checkCerts(name, protectionDomain.getCodeSource());17 return protectionDomain;18 }上面这段代码是 java.lang.ClassLoader 中 preDefineClass 方法的代码,注意一下第 9 行。 启动tomcat时的问题关于log4 treeviewer的事件问题单击事件怎么能分出是左右键点击的 程序设计的学习之路 JAVA里如何安全有效地停止(或者说销毁)线程?请指点,万分感谢! java反射的问题 请教图像处理的一个简单问题,请指教! ****急,请教,java中如何调用系统的应用程序?***** JTable数据模型共享数据 高分请教数据库....mysql!!!!在线! netty服务端如何向客户端发送消息 为什么我的摄像头在我的电脑上有RGB和HSV两种编码方式,在别人的电脑上就只有HSV一种呢? 求一个与排序有关的较好的算法
02 - not define java.* class,
03 - signer of this class matches signers for the rest of the classes in package.
04 */
05 private ProtectionDomain preDefineClass(String name, ProtectionDomain protectionDomain) {
06 if (!checkName(name))
07 throw new NoClassDefFoundError("IllegalName: " + name);
08
09 if ((name != null) && name.startsWith("java.")) {
10 throw new SecurityException("Prohibited package name: " + name.substring(0, name.lastIndexOf('.')));
11 }
12 if (protectionDomain == null) {
13 protectionDomain = getDefaultDomain();
14 }
15 if (name != null)
16 checkCerts(name, protectionDomain.getCodeSource());
17 return protectionDomain;
18 }上面这段代码是 java.lang.ClassLoader 中 preDefineClass 方法的代码,注意一下第 9 行。