Question

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

Was it helpful?

Solution

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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top