「javassist.NotFoundException: xxx.xxx.xxxService 」の解決対策

サンプルコード:
ClassPool pool = ClassPool.getDefault();
CtClass cls = pool.get(clazz.getName());

エラーメッセージ:
javassist.NotFoundException: xxx.xxx.xxxService

説明:
The default ClassPool returned by a static method ClassPool.getDefault() searches the same path that the underlying JVM (Java virtual machine) has. If a program is running on a web application server such as JBoss and Tomcat, the ClassPoolobject may not be able to find user classes since such a web application server uses multiple class loaders as well as the system class loader. In that case, an additional class path must be registered to the ClassPool.

解決対策
方法1
ClassPool pool = ClassPool.getDefault();
ClassClassPath classPath = new ClassClassPath(this.getClass());
pool.insertClassPath(classPath);

方法2
ClassPool pool = ClassPool.getDefault();
pool.appendClassPath(“E:\\xxx\\xxx\\target\\xxx_war\\WEB-INF\\lib\\xxx_jar-0.0.1-SNAPSHOT.jar");

Java

Posted by arkgame