0 Replies Latest reply on Apr 7, 2006 8:05 AM by Pieter Pareit

    Still using my old class

    Pieter Pareit Newbie

      Hi,

      I'm testing with javassist. Therefor I have created a little sample application.

      I'm running a JSF application on a JBoss server.

      ---------------------------HelloWorld Class ----------------------------

      package com.easypaygroup.easyweb.control.employee;

      public class HelloWorld {

      public void say(){
      System.out.println("say body");
      }

      }

      --------------------------- WebApplication JSF -------------------------

      /**
      Change the method say of my HelloWorld class
      **/
      public void jtest(){
      try {
      ClassPool cp = ClassPool.getDefault();
      cp.insertClassPath(new ClassClassPath(this.getClass()));

      CtClass cc = cp.get("com.easypaygroup.easyweb.control.employee.HelloWorld");

      CtMethod m = cc.getDeclaredMethod("say");
      m.insertBefore("System.out.println(\"*******************Begin***************************\");");
      m.insertAfter("System.out.println(\"*******************End***************************\");");
      cc.writeFile();
      } catch (IOException ex) {
      ex.printStackTrace();
      } catch (NotFoundException ex) {
      ex.printStackTrace();
      } catch (CannotCompileException ex) {
      ex.printStackTrace();
      }
      }

      /**
      Test my HelloWorld Class
      **/
      public void say(){
      HelloWorld emp = new HelloWorld();
      emp.say();
      }

      --------------------- END OF CODE ---------------------------
      After changing my HelloWorld class. I call the method say, the output I get is

      say body

      But I expect
      *******************Begin***************************
      say body
      "*******************End***************************

      Does somebody knows where I'm wrong?

      Thx in adv,
      Pieter