MANIFEST.MF agent configuration¶
The MANIFEST.MF file is a configuration file located in the META-INF directory within a JAR archive that serves as the core component for implementing a Java Agent^[600-developer__java__black-technology__javaagent.md]. It defines how the agent JAR interacts with the Java Virtual Machine (JVM) by declaring specific attributes required for the agent to load and function correctly^[600-developer__java__black-technology__javaagent.md].
Configuration Attributes¶
To function as a Java Agent, the manifest file must include specific entries that identify the agent class and define its operational capabilities.
Premain-Class¶
This attribute specifies the fully qualified class name of the agent class^[600-developer__java__black-technology__javaagent.md]. This class must contain a premain method, which is analogous to the standard main method but is invoked by the JVM before the application's actual main method executes^[600-developer__java__black-technology__javaagent.md]. This allows the agent to initialize and modify the environment as the application starts^[600-developer__java__black-technology__javaagent.md].
Can-Redefine-Classes¶
This boolean attribute indicates whether the agent is capable of redefining classes at runtime^[600-developer__java__black-technology__javaagent.md]. When set to true, it grants the agent permission to modify the bytecode of existing classes, which is a technique often used for Bytecode Instrumentation or profiling^[600-developer__java__black-technology__javaagent.md].
Example Configuration¶
Below is an example of a valid MANIFEST.MF entry for a Java Agent^[600-developer__java__black-technology__javaagent.md]:
Manifest-Version: 1.0
Premain-Class: tk.tommy.MyAgent
Can-Redefine-Classes: true
Related Concepts¶
- Java Agent
- Bytecode instrumentation
- [[Aspect-oriented programming (AOP)]]
Sources¶
- 600-developer__java__black-technology__javaagent.md