I have been trying to use Javassist and am having problems trying to use ClassPool.get() for a class that will be loaded by my own ClassLoader. It fails with the NotFoundException indicating the class could not be loaded. I know the MyInterface Class is loadable via my classloader as I can use my classloader directly to load the class.
The code is as follows:
cPool = ClassPool.getDefault(); java.lang.ClassLoader cll = this.getClass().getClassLoader(); cPool.appendClassPath( new LoaderClassPath( cll ) ); serializableClass = cPool.get( "java.io.Serializable" ); CtClass iClass = cPool.get( "myPackage.MyInterface" );
A difference between 2.6 and 3.0beta is that ClassPool#get() in 3.0beta
calls ClassLoader#getResource() although 2.6 calls
ClassLoader#getResourceAsStream().
If you use 3.0beta, your ClassLoader must define both getResource()
and getResourceAsStream().
I'll put this info into javadoc.
As for release schedule, 3.0RC1 will be released by this weekend.
I recommend 3.0RC1, which will be fully compatible to 3.0.