[英]Wrong name error when class loaded from random dir
I want to make a instance of.class file located into random directory.我想在随机目录中创建一个.class 文件的实例。 I tried this
我试过这个
private final String CLASS_FOLDER =
"C:\\Users\\test\\Desktop\\fix\\core\\src\\test\\org\\poc\\";
private Class getClassFromFile(String fullClassName) throws Exception {
URLClassLoader loader = new URLClassLoader(new URL[] {
new URL("file://" + CLASS_FOLDER)
});
return loader.loadClass("Order");
}
When I run the code I get error:当我运行代码时出现错误:
java.lang.NoClassDefFoundError: Order (wrong name: com/solutions/backend/toms/actions/Order)
Looks like a security check for correct package name.看起来像是对正确 package 名称的安全检查。 Is there nay way to skip this check because I need to load.class files into random directories?
有没有办法跳过此检查,因为我需要将.class 文件加载到随机目录中?
Java classes need to be in a directory hierarchy that matches their package
. Java 类需要位于与其
package
匹配的目录层次结构中。 You cannot drop a Java .class
in a "random" directory, that's simply not how classloading works.您不能将 Java
.class
放在“随机”目录中,这根本不是类加载的工作方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.