MANIFEST.MF configuration¶
MANIFEST.MF configuration is a specific setup within the META-INF/MANIFEST.MF file required to bundle and execute a Java Agent.^[600-developer__java__black-technology__javaagent.md]
Overview¶
To function as a Java Agent, code must be packaged into a JAR file^[600-developer__java__black-technology__javaagent.md]. Within this JAR, the MANIFEST.MF file serves as the control point that defines the agent's entry class and its capabilities at runtime^[600-developer__java__black-technology__javaagent.md].
Configuration Attributes¶
The manifest file must contain specific key-value pairs to enable the agent to intercept class loading before the application's main method executes^[600-developer__java__black-technology__javaagent.md]:
Premain-Class: This attribute specifies the fully qualified class name of the agent^[600-developer__java__black-technology__javaagent.md]. This class must contain apremainmethod that acts as the entry point, executing prior to the target application'smainmethod^[600-developer__java__black-technology__javaagent.md].Can-Redefine-Classes: This boolean attribute indicates whether the agent is capable of redefining classes (modifying bytecode) at runtime^[600-developer__java__black-technology__javaagent.md].
Execution¶
Once configured and packaged, the agent is invoked by passing the -javaagent option to the JVM^[600-developer__java__black-technology__javaagent.md].
java -javaagent:myagent.jar=thisIsAgentArgs -jar thisIsMain.jar^[600-developer__java__black-technology__javaagent.md]
Related Concepts¶
- javaagent
- [[Bytecode Manipulation]]
Sources¶
600-developer__java__black-technology__javaagent.md