Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How I can make Javassist work with Tomcat

I want to perform bytecode instrumentation on servelets using Javassist, but the challenge is that, whatever instrumentation I did, it is not reflected in Tomcat classes. I could clearly see that this is an issue with class loaders but I couldn't make it even work with custom class loaders. I tried searching for any examples on this but couldn't find any. Do you have any examples on how we can make Tomcat work with Javassist?

like image 562
ravi k Avatar asked Nov 25 '25 01:11

ravi k


1 Answers

I assume that you are using ClassPool.getDefault() in order to run your example on Tomcat. This will not work as application servers do not run on the class path.

In order to inform Javassist of the classes of a specific application, you need to append the classes of the current class loader. You can do this by appending an instance of LoaderClassPath to the current class pool which references your application's class loader.

like image 84
Rafael Winterhalter Avatar answered Nov 28 '25 02:11

Rafael Winterhalter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!