Tutorials about javaagents [closed]

The second case talks about Java Instrumentation API - this link points to a Javadoc which is rather descriptive.

And here, is the full instruction and an example of how to create java instrumentation agent.

The main concept is to:

  1. Implement a static premain (as an analogy to main) method, like this:

    import java.lang.instrument.Instrumentation;
    
    class Example {
        public static void premain(String args, Instrumentation inst) {
            ...
        }
    }
    
  2. Create a manifest file (say, manifest.txt) marking this class for pre-main execution. Its contents are:

    Premain-Class: Example
    
  3. Compile the class and package this class into a JAR archive:

    javac Example.java
    jar cmf manifest.txt yourAwesomeAgent.jar *.class
    
  4. Execute your JVM with -javaagent parameter, like this:

    java -javaagent:yourAwesomeAgent.jar -jar yourApp.jar
    

Few useful resources for the javaagent as described in point #2.