Search code examples
javajavaagentsjdk1.7

java -javaagent: printing java command use guidelines


I'm trying to set a new agent using:

java -javaagent:agent.jar

When I run I see the java usage message.

MANIFEST.MF:

Manifest-Version: 1.0
Created-By: 1.7.0_79 (Oracle Corporation)
Premain-Class: org.mypackage.Agent

Solution

  • java command is used to run some java application. Java agents are not standalone applications that you run directly. They are "added" to your normal application to add some extra behaviour.

    So if you have your application packaged as a jar file then you run

    java -javaagent:agent.jar -jar myApp.jar
    

    If you have just a bunch of compiled classes you run something like

    java -javaagent:agent.jar -cp . my.package.MyMainClass