Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javassist.NotFoundException error in Spring framework project using Javassist - Need help knowing how to set classpath and class name

I'm using javassist on a model: com.project.model.Model I've tried various combinations of how the Strings should be formatted for the ClassPath and the CtClass, but to no avail.

    ClassPool pool = ClassPool.getDefault();
    String setClassPath = "/com/project/model/";
    pool.insertClassPath(setClassPath);
    CtClass ctClass = pool.get("Model.java");

How should these Strings be formatted? I am using WebSphere Application Server 8.5.5.1, JVM 1.7, spring-webmvc 3.2

Thanks in advance.

like image 554
user3776722 Avatar asked Jan 11 '23 07:01

user3776722


1 Answers

Figured it out by grabbing the classpath of the an instance of Model:

Model model = new Model();
ClassPool pool = ClassPool.getDefault();
ClassClassPath ccpath = new ClassClassPath(model.getClass());
pool.insertClassPath(ccpath);
CtClass ctClass = pool.get("com.project.Model");
like image 149
user3776722 Avatar answered Jan 28 '23 09:01

user3776722