Home > Java > javaTutorial > Java uses agent to implement the code example before the main method

Java uses agent to implement the code example before the main method

黄舟
Release: 2018-05-18 10:58:26
Original
1755 people have browsed it

This article mainly introduces relevant information about the detailed examples before Java uses agent to implement the main method. I hope this article can help everyone understand this part of the content. Friends in need can refer to it

Java uses agent to implement the detailed example before the main method

Create the Agent project

PreMainExecutor class, execute this method before the main method

public class PreMainExecutor {

  public static void premain(String agentOps, Instrumentation inst){
    System.out.println("premain execute..........");
  }

}
Copy after login

META- INF/MANIFEST.MF

Manifest-Version: 1.0
Premain-Class:test.agent.PreMainExecutor
Copy after login

is packaged into JavaAgent.jar and placed on the D drive.

Test class

Test class.

public class Test {

  public static void main(String[] args){
    System.out.println("main..........");
  }

}
Copy after login

Execution

java -javaagent:JavaAgent.jar Test
Copy after login

Output

premain execute..........
main..........
Copy after login

The above is the detailed content of Java uses agent to implement the code example before the main method. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template