Create a BCEL JavaClass object from arbitrary .class file
Asked Answered
A

3

5

I'm playing around with BCEL. I'm not using it to generate bytecode, but instead I'm trying to inspect the structure of existing compiled classes.

I need to be able to point to an arbitrary .class file anywhere on my hard drive and load a JavaClass object based on that. Ideally I'd like to avoid having to add the given class to my classpath.

Anatolio answered 2/10, 2008 at 20:13 Comment(0)
A
11

The straightforward way is to create a ClassParser with the file name and call parse(). Alternatively you can use SyntheticRepository and supply a classpath (that is not your classpath, IYSWIM).

Ance answered 2/10, 2008 at 20:20 Comment(0)
T
3

The existing .class can be class loaded to java lang class object. Then it can be converted into BCEL intermediate javaclass structure. The following code may help:-

Class<?> javaClass1 = null;
javaClass1 = ucl.loadClass("com.sample.Customer");
org.apache.bcel.classfile.JavaClass javaClazz1=org.apache.bcel.Repository.lookupClass(javaClass1);
Trailer answered 7/10, 2015 at 5:56 Comment(0)
A
2
new ClassParser(classfilebytearrayhere).parse()
Allogamy answered 1/6, 2012 at 22:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.