最小java代理的问题
我似乎无法让一个简单的代理工作,这让我很沮丧...
代理将起作用的类:
public class Hello {
public static void main(String[] args) {
System.out.println("Hello from main");
}
}
代理类:
package instrumentation;
public class Agent {
public static void premain(String args,
Instrumentation inst) throws IOException {
System.out.println("Hello from agent");
}
}
MANIFEST.MF:
Premain-Class: instrumentation.Agent
已传递 JVM 参数:
-javaagent:C:\path\to\agent.jar
我得到的唯一输出是:
Hello from main
我是什么做错了吗?
I can't seem to get a simple agent to work and it's frustrating me quite a bit...
Class upon which agent will act:
public class Hello {
public static void main(String[] args) {
System.out.println("Hello from main");
}
}
Agent class:
package instrumentation;
public class Agent {
public static void premain(String args,
Instrumentation inst) throws IOException {
System.out.println("Hello from agent");
}
}
MANIFEST.MF:
Premain-Class: instrumentation.Agent
JVM argument passed:
-javaagent:C:\path\to\agent.jar
The only output I get is:
Hello from main
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有趣的是,放置
javaagent
参数的位置很重要;它必须位于jar
参数之前。所以尝试一下:
当然,假设您的 java 代理与您的源代码一起打包。
Funny enough, the position at which you place your
javaagent
argument matters; It must come before thejar
argument.So try this:
Assuming your java agent is packaged along with your source, of course.