Community
Participate
Working Groups
Build Identifier: eclipse3.6.1 Hello I am trying to use javassist in eclipse. I have added javassist.jar file to project. I can import the classes in javassist package. but for a simple program getting an error in the ClassPool.get method. NotFoundException. Here are the program details. package temp; public class Hello { public void say() { System.out.println("Hello"); } } __________________________________________ // 2nd program tries to modify the bytecode of Hello. package temp; import javassist.ClassPool; import javassist.CtClass; import javassist.CtMethod; public class Test { public static void main(String[] args) throws Exception { ClassPool cp = ClassPool.getDefault(); CtClass cc = cp.get("Hello"); // getting NotFoundException here.. CtMethod m = cc.getDeclaredMethod("say"); m.insertBefore("{ System.out.println(\"Hello.say():\"); }"); Class c = cc.toClass(); Hello h = (Hello)c.newInstance(); h.say(); System.out.println("test prog:"); } } Reproducible: Always Steps to Reproduce: 1.create temp package. 2.Copy Hello.java program in eclipse. 3.Copy Test.java program in eclipse. 3.Add javassist.jar file through buildpath option. 4. execute Test.java
This should belong to JDT/Core
You need to put "temp.Hello" for the class name as your class belongs to a named package "temp". Once you have: package temp; import javassist.ClassPool; import javassist.CtClass; import javassist.CtMethod; public class Test { public static void main(String[] args) throws Exception { ClassPool cp = ClassPool.getDefault(); CtClass cc = cp.get("temp.Hello"); // getting NotFoundException here.. CtMethod m = cc.getDeclaredMethod("say"); m.insertBefore("{ System.out.println(\"Hello.say():\"); }"); Class c = cc.toClass(); Hello h = (Hello) c.newInstance(); h.say(); System.out.println("test prog:"); } } your code runs fine. Closing as INVALID.