-
1. Re: can javassist modify class in memory?
chiba Aug 14, 2003 2:19 AM (in response to tealeaf)You have to load a modified class if you want
to see the effects. There is no way to directly
modify a class in the JVM memory. -
2. Re: can javassist modify class in memory?
tealeaf Aug 14, 2003 3:13 PM (in response to tealeaf)Thank you for your reply! Is the same true with BCEL library as well? Is that a fundamental JVM restriction?
So, theoretically speaking, if the app runs from a CD-ROM or some other read-only store, you'd have to save the class to an in-memory ByteArrayOutputStream and load it? I don't know much about this. Is that something that's done all the time to achieve on the fly modification? -
3. Re: can javassist modify class in memory?
hlship Aug 15, 2003 7:19 AM (in response to tealeaf)Tapestry does a lot of Javassist-based class enhancement. It leaves the original class alone and creates a subclass. Often the starting class is abstract, and Tapestry uses Javassist to fill in the abstract methods.
Javassist allows you to create and configure a CtClass instance and then use that to create a java.lang.Class you can instantiate.
If you want to do something more aspect-like, you can do a lot of juggling of class loaders to ensure that Javassist has a chance to enhance the bytecodes before they are converted into a java.lang.Class; I believe the tutorial discusses how to fit Javassist into the pipeline (but this wasn't something I needed for my work, so I haven't investigated it). -
4. Re: can javassist modify class in memory?
tealeaf Aug 15, 2003 12:49 PM (in response to tealeaf)Ah, I think I understand. Thank you for your reply!
-Leo