J
Joe
I'm using BCEL in conjunction with a custom classloader to dynmically
modify the bytecode of a class as it's loaded.
I'm now considering the problems I'm going to face when using such a
mechanism inside an application server such as Tomcat.
I need to do the following on application startup (e.g. in a main
method for command-line, or in a Servlet class when used in a web
app):
1. Load and parse a configuration file, listing a number of classes
2. For each class, load it via a custom class loader and modify the
bytecode
3. Ensure that everywhere in the application that such a class is
reference (e.g. through new MyClass()), my modified version is used.
What's worrying me is that although I initially load and modify the
classes using my Custom ClassLoader, when they are referred later in
the application (eg. in a Servlet call), a different ClassLoader will
be used (ie. the Tomcat webapp thread one), so I'll end up with a
different, unmodified class.
Am I right in thinking that this is what'll happen? If so, what can I
do to avoid it (short of pre-processing the classes and storing the
modified class files)?
modify the bytecode of a class as it's loaded.
I'm now considering the problems I'm going to face when using such a
mechanism inside an application server such as Tomcat.
I need to do the following on application startup (e.g. in a main
method for command-line, or in a Servlet class when used in a web
app):
1. Load and parse a configuration file, listing a number of classes
2. For each class, load it via a custom class loader and modify the
bytecode
3. Ensure that everywhere in the application that such a class is
reference (e.g. through new MyClass()), my modified version is used.
What's worrying me is that although I initially load and modify the
classes using my Custom ClassLoader, when they are referred later in
the application (eg. in a Servlet call), a different ClassLoader will
be used (ie. the Tomcat webapp thread one), so I'll end up with a
different, unmodified class.
Am I right in thinking that this is what'll happen? If so, what can I
do to avoid it (short of pre-processing the classes and storing the
modified class files)?