Reputation: 1309
I have a jar file containing multiple .class files. Each .class file has several methods in it. Now, while the jar is executing, i.e. during runtime, I want to intercept the methods with an external user defined method. That is, I want to run an external method before or after each method call in my jar classes.
I have looked into Spring-AOP, but it says I need to declare the classes in the Spring context and hence the classes will be called with their methods in the sequence in which it is written in the Spring context.
But I want the execution flow to be that of the original jar webapp.
Can you share with me anything which can be used to achieve what I explained above? Thanks in advance!
Upvotes: 1
Views: 1410
Reputation: 136022
You can use JVM instrumentation API, it allows you to modify classes being loaded using some library like http://commons.apache.org/proper/commons-bcel/. See example here https://web.archive.org/web/20181012004753/http://blog.javabenchmark.org/2013/05/java-instrumentation-tutorial.html
Upvotes: 2