Created
June 6, 2018 20:59
-
-
Save jeffrade/f2ca62da8e49e18e8a375d2a67a56304 to your computer and use it in GitHub Desktop.
How to create a `javaagent` executable jar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.lang.instrument.Instrumentation; | |
/** | |
* Let's say you have an existing application that is an executable jar file (e.g. app.jar) | |
* Define this class a directory of your choosing. | |
* Then create the following manifest.txt file: | |
* <code> $ echo "Premain-Class: ExampleAgent" > manifest.txt</code> | |
* Then create the jar file for this class: | |
* <code> $ jar cmf manifest.txt example-agent.jar *.class</code> | |
* Lastly, start your existing app.jar like so: | |
* <code> $ java -javaagent:/full/path/to/example-agent.jar -jar app.jar</code> | |
*/ | |
class ExampleAgent { | |
public static void premain(String args, Instrumentation inst) { | |
System.out.println("################################ in premain"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment