I've got .class
file. I want to open it by javassist
, add class annotation and save. How can I get CtClass
instance from .class
file?
ps. I don't know its dependencies / package / name
To get the CtClass
from a class file you can use the method ClassPool.makeClass
. This method takes as an argument an input stream from which it reads the class file.
import javassist.ClassPool;
import javassist.CtClass;
ClassPool pool = ClassPool.getDefault();
CtClass ctClass = pool.makeClass(new FileInputStream("pathTo\Test.class"));
System.out.println(ctClass);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.