Various technical articles, IT-related tutorials, software information, and development journals
Friday, June 14, 2019
BCEL Repository.lookupClass can't find dynamically generated classes
Recently I used Apache BCEL (Bytecode Engineering Library) to modify classes and load the altered versions. That process starts with Repository.lookupClass call to get a BCEL JavaClass instance representing a class. However, when I tried to do that to a dynamically generated class (actually one that had already been through an editing process) rather than one loaded normally by the system classloader, it couldn't find the class. If I understand correctly, lookupClass searches the application classpath and loads a .class file from disk? That will clearly not work for anything dynamically generated, so the alternate route of passing a byte stream to ClassParser is needed. This works if you can keep track of the bytecode of the edited classes you create, but isn't possible for classes created by others.
Labels:
java
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment