[jboss-user] [Javassist] - Compile problem with interface initialization

Enrico Palazzo do-not-reply at jboss.com
Thu Jul 19 11:31:40 EDT 2012


Enrico Palazzo [https://community.jboss.org/people/pulce] created the discussion

"Compile problem with interface initialization"

To view the discussion, visit: https://community.jboss.org/message/749098#749098

--------------------------------------------------------------
Hi there! I implemented code to my project that makes use of javassist. However, I constantly fail to implement an interface to a new class I create. Here is the code I use (adapted from  http://www.javaranch.com/journal/200711/Journal200711.jsp#a4): http://www.javaranch.com/journal/200711/Journal200711.jsp#a4):


*Main file:*
package test;
import javassist.*;
public class Example2 {
     public static void main (String[] args) throws Exception {
        ClassPool pool = ClassPool.getDefault();
        CtClass evalClass = pool.makeClass("Eval"+System.currentTimeMillis());
       evalClass.setInterfaces(new CtClass[] { pool.makeClass("Evaluator") });
       evalClass.addMethod(CtNewMethod.make("public double eval (double x) { return (x*x-x) ; }", evalClass));
       Class clazz = evalClass.toClass();
       Evaluator obj  = (Evaluator) clazz.newInstance();
       double result = obj.eval(4);
       System.out.println(result);
    }
}

*Interface "Evaluator":*
package test;
public interface Evaluator {
     public double eval (double x);
 }

 The code works like a charm in the default package of an Eclipse project (without package test; of course). However, when I use it in a package, I get an Error:
javassist.CannotCompileException: by java.lang.NoClassDefFoundError: Evaluator 

>From trial and interpreting different error messages I guess that the class loader that should load "Evaluator" refers to the /bin path, while the Evaluator.class file is to be found in the /bin/test folder. Is there a way to solve that? Many thanks in advance!
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/749098#749098]

Start a new discussion in Javassist at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2062]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20120719/02eba63b/attachment-0001.html 


More information about the jboss-user mailing list