gpt4 book ai didi

java - 在 'fat jar' 内指定 java 代理?

转载 作者:行者123 更新时间:2023-12-01 10:36:34 25 4
gpt4 key购买 nike

我正在使用 jetty-alpn-agent为我的项目添加 ALPN 支持,但我能找到的只是有关如何从 .m2 运行它的说明文件夹,这使我需要部署两个 jar:s 而不是我的一个 uber-jar,从而使其便携性降低。

是否可以将 jar 内的位置指定给 -javaagent 开关?

我正在寻找类似 java -javaagent:my.jar!/javaagents/jetty-alpn-agent-2.0.0.jar -jar myjar.jar 的东西,但这似乎不起作用。

最佳答案

根据 java.lang.instrumentation 可能是可能的文档。

如果实现允许它jetty-alpn-agent.jar必须是系统类路径的一部分。所以你必须把它包含在你的 my.jar 中像任何其他应用程序库一样。

Starting Agents After VM Startup

An implementation may provide a mechanism to start agents sometime after the the VM has started. The details as to how this is initiated are implementation specific but typically the application has already started and its main method has already been invoked. In cases where an implementation supports the starting of agents after the VM has started the following applies:

The manifest of the agent JAR must contain the attribute Agent-Class. The value of this attribute is the name of the agent class.

The agent class must implement a public static agentmain method.

The system class loader ( ClassLoader.getSystemClassLoader) must support a mechanism to add an agent JAR file to the system class path.

The agent JAR is appended to the system class path. This is the class loader that typically loads the class containing the application main method. The agent class is loaded and the JVM attempts to invoke the agentmain method. The JVM first attempts to invoke the following method on the agent class:

public static void agentmain(String agentArgs, Instrumentation inst);

If the agent class does not implement this method then the JVM will attempt to invoke:

public static void agentmain(String agentArgs);

The agent class may also have an premain method for use when the agent is started using a command-line option. When the agent is started after VM startup the premain method is not invoked.

The agent is passed its agent options via the agentArgs parameter. The agent options are passed as a single string, any additional parsing should be performed by the agent itself.

The agentmain method should do any necessary initialization required to start the agent. When startup is complete the method should return. If the agent cannot be started (for example, because the agent class cannot be loaded, or because the agent class does not have a conformant agentmain method), the JVM will not abort. If the agentmain method throws an uncaught exception it will be ignored.



PS:这个我没试过。请让我知道它是否有效。

关于java - 在 'fat jar' 内指定 java 代理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39033599/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com