This page contains an archived post to the Java Answers Forum made prior to February 25, 2002.
If you wish to participate in discussions, please visit the new
reading classes from zip / jar file using custom class loader
Posted by John on December 10, 2000 at 3:16 PM
I'm using a custom class loader to read classes from a zip/ jar file on NT sp4. This works for simple classes. If I try reading a more complex class, the binary data I get back from the zip / jar file for the respective class cannot be parsed properly (method defineClass throws ClassFormatError with "Illegal constant pool type" for jdk1.1.8 or "Illegat UTF8 string in constant pool" for jdk1.2.2-006). If I read the .class file directly from disk, it works fine so the problem must be in how the inputStream returned by zipFile.getInputStream(zipEntry) reads the bytes. The class bytes read from a jar /zip file are different then if read directly from the .class on disk. All the examples that use custom class loaders that I've seen don't read a in a .class file from an archive. Now I don't see this reported as a bug, but it could be that no one's tried reading from an archive via a custom class loader. Obviously, the primordial class loader is able to define classes as read from archives, but it's not using the java.util.zip or java.util.jar classes to perfom this task.
Any help would be greatly appreciated.