I am generating classes that need to access protected fields from other existing classes. Because of this, I am in need of specifying the classpath that it should end up in.
Does anyone know how to do this in Javassist?
An old question but I have come across the same problem. The solution is to use full class name, including the package, when creating the class.
ClassPool pool = ClassPool.getDefault();
String packageName = "yourpackage.";
String className = "NameOfTheClass";
CtClass dynamicClass = pool.makeClass(package+className);
This way you will be able to access protected fields of classes from the given package.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With