OK, maybe the 4th section of the tutorial should be revised to clarify
the points (In fact, I assumed that the readers know Java's class loader
mechansim when I wrote that section.)
Anyway, to do what you (maybe) want to do, you must create a new
instance of javassist.Loader (or your own class loader) and run *all*
your classes including modified ones and not-modified ones with that
instance of the class loader. Please read Section 4.2 of the tutorial
again (there was typos; sorry please read a copy on the web site.)
To use modifeid B with A (I mean, your example), use the following
MyTranslator:
| public class MyTranslator implements Translator {
| void start(ClassPool pool)
| throws NotFoundException, CannotCompileException { /* ignore */ }
| void onLoad(ClassPool pool, String classname)
| throws NotFoundException, CannotCompileException
| {
| if (classname.equals("B") {
| CtClass cc = pool.get("B");
| cc.setModifiers(Modifier.PUBLIC); // or whatever you want
| }
| }
| }
|
And run the main class such as:
| public class Main2 {
| public static void main(String[] args) throws Throwable {
| Translator t = new MyTranslator();
| ClassPool pool = ClassPool.getDefault();
| Loader cl = new Loader();
| cl.addTranslator(pool, t);
| cl.run("MyApp", args);
| }
| }
|
in the regular way (# java Main2 ...).
MayApp is the name of the class for launching the application using
modified B. It can be "A" or "B" if "A" or "B" includes main().
javassist.Loader dynamically(?) modifes the class file of B when
it is loaded.
Does this example help you? If so, I'll add this example to the tutorial.
View the original post :
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3842567#3842567
Reply to the post :
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3842567
-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=4721&alloc_id=10040&op=click
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user