最小java代理的问题

发布于 2025-01-13 12:22:13 字数 670 浏览 2 评论 0原文

我似乎无法让一个简单的代理工作,这让我很沮丧...

代理将起作用的类:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

另类 2025-01-20 12:22:13

有趣的是,放置 javaagent 参数的位置很重要;它必须位于 jar 参数之前。

所以尝试一下:

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

当然,假设您的 java 代理与您的源代码一起打包。

Funny enough, the position at which you place your javaagent argument matters; It must come before the jar argument.

So try this:

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

Assuming your java agent is packaged along with your source, of course.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文