java-instrumentation
Описание
Simple example of using java instrumentation for modifications of byte-code at runtime
Языки
- Java100%
readme.md
Java-agent
Simple example of using java instrumentation
Package that provides services to allow instrumentation is java.lang.instrument
The mechanism provides the possibility of modification of byte-code at runtime.
Main components
myapp
Simple hello world application
agent
Application which will modify origin code of myapp.
Contains:
- MyAgent class with premain() method
- MyTransformer class which implements ClassFileTransformer interface and its method transform()
What's going on
The agent connects to the application, integrates into its method, and adds text output after executing the original method
What we need
myapp
- maven-jar-plugin
- settings for manifest file
agent
- maven-assembly-plugin
- settings for building jar-with-dependencies
- settings for premain class in manifest
- javassist dependency (perform operations on the bytecode )
Building results
Two jars with MANIFEST.MF files
myapp
agent
Run
Some hints
If it is needed to get some arguments in premain method (name of the certain class or method which will be updated by agent):