wood burning stoves 2.0*
The moose likes Java in General and the fly likes loading class files from jar files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "loading class files from jar files" Watch "loading class files from jar files" New topic
Author

loading class files from jar files

Patrick Cobbett
Ranch Hand

Joined: Jul 10, 2003
Posts: 44
Hello all,
I am trying to load class files within a jar file. The program extracts and iterates through all the ZipEntrys. For each ZipEntry i obtain the InputStream and read in the contents of each class file in to a byte array. I've made a ClassLoader which relaxes the access rights to the define method which take an array of bytes: Class defineClass(String name, byte[] data, int start, int end);
However only certain classes correctly return a Class objects. The majority of class files i try to read in this manner throws a ClassFormatException with one if the following messages:
Illegal constant pool type
Illegal UTF8 string in constant pool
Illegal constant pool index
Arguments can't fit into locals
any ideas?


[SCJP, SCJD]
sander hautvast
Ranch Hand

Joined: Oct 18, 2002
Posts: 71
you've probably done sth like: inputStreamInstance.read(byte[] b)
like me...
This is what you should do:
new DataInputStream(inputStreamInstance).readFully(byte[] b)
I don't really know why because the apidoc for both methods looks the same. But it works!
[ May 06, 2004: Message edited by: sander hautvast ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: loading class files from jar files
 
Similar Threads
Study Notes from a person who secured 100%.
Reading and Writing from Large File, OutOfMemory
Question on loading class from Jar File
NX: Reading from the db.db file
Pblm with JAR/InputStream