且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

自定义Java类加载器和内部类

更新时间:2023-11-17 13:10:10

我看来您可能没有覆盖 ClassLoader.findClass().否则,您要扩展的 ClassLoader 不知道如何找到这些类.

I looks like you may not be overriding ClassLoader.findClass(). Without doing that, the ClassLoader you are extending does not know how to find these classes.

使用仅在该类的私有静态Map< String,Class<?>> 中查找的内容覆盖该函数.加载每个类时,将其放入该地图.

Override that function with something that simply looks up in a private static Map<String, Class<?>> for the class. As you load each class, put it into that map.

困难在于按正确的顺序加载类,因为当前的实现方式不允许您跳回搜索Zip并从新的 findClass()方法.

The difficulty will be in loading classes in the correct order, as your current implementation will not allow you to jump back to searching the Zip and calling defineClass() from your new findClass() method.