I have this method (in my own classloader) that loads classes from zip:
ZipInputStream in = new ZipInputStream(new FileInputStream(zip));
ZipEntry entry;
while ((entry = in.getNextEntry()) != null) {
if (!entry.isDirectory()) {
byte[] buffer = new byte[(int) entry.getSize()];
in.read(buffer);
if (!entry.getName().endsWith(".class"))
continue;
String name = entry.getName().replace(".class", "").replace("/", ".");
Class<?> cls = this.defineClass(name, buffer, 0, buffer.length);
this.resolveClass(cls);
}
}
The zip that im trying to load looks like this:
TestClass.class
TestClass$SomeOtherInnerClass.class
My problem is that defineClass() fails to load the TestClass$SomeOtherInnerClass. If this class is loaded before the actual TestClass i get this:
java.lang.NoClassDefFoundError: TestClass
I also tried to load the TestClass.class first but then im getting this error:
java.lang.ClassFormatError: Wrong InnerClasses attribute length in class file TestClass
Is there something i'm doing wrong?