hi guys,
i am adding new field and its getter and setter methods to an existing class.
I can see those new changes in the bytecode, but unable to access those getter 
and setter. I know that the jvm which loaded the class is old,  but how to load 
new byte code class
here is my code

                ClassPool classPool = ClassPool.getDefault();
                CtClass ctClass = null;
                ctClass = 
classPool.get("com.cura.hibernate.annotations.Employ");
                ClassFile classFile = ctClass.getClassFile();

                ConstPool constPool = classFile.getConstPool();

                AnnotationsAttribute attr = new AnnotationsAttribute(constPool,
                                AnnotationsAttribute.visibleTag);
                Annotation a = new Annotation("javax.persistence.Column", 
constPool);
                a.addMemberValue("name", new StringMemberValue("EmployAddress",
                                constPool));
                // attr.setAnnotation(a);

                // classFile.addAttribute(attr);

                CtField make = CtField.make("private String employAddress;", 
ctClass);
                CtField ctField = new CtField(make, ctClass);

                // ctField.setAttribute("Author1", ctClass.toBytecode());

                JavassistUtils javassistUtils = new JavassistUtils();
                javassistUtils.addFieldAnnotation(ctField, a);

                ctClass.addField(ctField);

                CtMethod setter = CtNewMethod
                                .make(
                                                "public void 
setEmployAddress(String employAddress) { this.employAddress = employAddress; }",
                                                ctClass);

                CtMethod getter = CtNewMethod.make(
                                "public String getEmployAddress() { return 
employAddress; }",
                                ctClass);

                ctClass.addMethod(getter);

                ctClass.addMethod(setter);
                ctClass.writeFile("bin");
                ctClass.rebuildClassFile();
                
            
//           Loader cl = new Loader(classPool);
//
//           CtClass ct = 
classPool.get("com.cura.hibernate.annotations.Employ");
//           
//
//           Class c = cl.loadClass("com.cura.hibernate.annotations.Employ");
//           Object rect = c.newInstance();
             


//              Class class1 = ctClass.toClass();
                
                
                byte[] byteCode = ctClass.toBytecode();
                HotSwapper hotSwapper = new HotSwapper(8000);// 8000 is a port 
number.
                hotSwapper.reload("com.cura.hibernate.annotations.Employ", 
byteCode);


i have write with hotwapper and also with custom loader class to load .

Please can anyone direct me in this situation.

Thank You


View the original post : 
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4269230#4269230

Reply to the post : 
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4269230
_______________________________________________
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to