Hello all,
I'm trying to use javassist to create a new class at the execution.
I have a class named TranslatorConstructor and this one should create a class Translator. This class is composed of a field. This field is of IBinaryOutputFile type (personnal one). So when I get ClassPool thanks to ClassPool.getDefault, I do pool.importPackage with my own package "tools.IBinaryOutputFile". The problem is that doesn't work... Even if I use a class BinaryOutputFile and not an interface...
I'm using eclipse and I configure my project with javassist as an external jar. I'm wondering if it was a good idea because I don't know how javassist does to find my class...
public TranslatorConstructor (String className) {
ClassPool pool = ClassPool.getDefault();
pool.importPackage("tools.interfaces.IBinaryOutputFile");
pool.importPackage("tools.BinaryOutputFile");
clazz = pool.makeClass(className);
}
public void init () throws CannotCompileException {
String fieldName = "private IBinaryOuputFile binaryFile;";
CtField field = CtField.make(fieldName, clazz);
clazz.addField(field);
When I create the field, an exception occured...
clazz is a class field a TranslatorConstructor affected in the constructor with makeClass.
If anyone has an idea about why it doesn't work, it would be great.
Thank you !
--
VanishedMan