简体   繁体   English

如何将 jar 添加到 Windows 中的 jconsole 类路径?

[英]How do I add a jar to jconsole classpath in windows?

I'm trying to invoke a JMX MBean via Jconsole , but the method that I'm calling receive an object that needs to be on jconsole classpath in order to work.我正在尝试通过Jconsole调用JMX MBean ,但是我调用的方法接收一个需要在jconsole 类路径上才能工作的对象。

I've tried this and the jconsole does not open (and no error is shown):我试过这个,但 jconsole 没有打开(并且没有显示错误):

jconsole -J-Djava.class.path=%JAVA_HOME%\lib\jconsole.jar;path_to_newjar_\newjar.jar

Take jconsole.jar out of the -J classpath.从 -J 类路径中取出 jconsole.jar。 It's already set in the jconsole launcher.它已经在 jconsole 启动器中设置。

===== Update ===== ===== 更新 =====

Hmmm.... I take back my suggestion.嗯……我收回我的建议。 I have a windows batch file I use [which works] which adds a JAR to the classpath.我有一个 Windows 批处理文件,我使用 [which works] 将 JAR 添加到类路径。 The intent is to add the JMXMP JMX client into jconsole and then launch to the argument specified JMX Service URL.目的是将JMXMP JMX 客户端添加到 jconsole 中,然后启动到参数指定的 JMX 服务 URL。 It looks like this:它看起来像这样:

@echo off
start /B jconsole -J-Djava.class.path=%JAVA_HOME%\lib\jconsole.jar;MY-JAR-PATH\jmx-optional-1.0-b02-SNAPSHOT.jar service:jmx:jmxmp://localhost:%1

If a command like that does not work (ie jconsole still will not launch, but does not error out either), then you need to figure out where it is stalling.如果这样的命令不起作用(即 jconsole 仍然不会启动,但也不会出错),那么您需要弄清楚它在哪里停止。 2 suggestions for this: 2 对此的建议:

  1. Launch another jconsole and attach to the stalled jconsole by PID, switch to the Threads tab and eyeball what's going on in the main thread.启动另一个 jconsole 并通过 PID 附加到停滞的 jconsole,切换到 Threads 选项卡并注意线程中发生的事情。
  2. Or, (since it looks like you're in windows) hit Ctrl-Break and hopefully it will print out a thread dump to the console and you can then eyeball the main thread going-ons there.或者,(因为它看起来像是在 Windows 中)按 Ctrl-Break并希望它会将线程转储打印到控制台,然后您可以观察那里的线程。

Post back if you get anything (or if you don't....)如果你得到任何东西(或者如果你没有......)

If you want to have access to both local & remote processes, the above answers are still missing a step.如果您想同时访问本地和远程进程,上述答案仍然缺少一步。

From the Java 8 oracle docs:来自 Java 8 oracle 文档:

If the JMX agent uses a connector which is not included in the Java platform, you need to add the connector classes to the class path when you run the jconsole command, as follows.如果 JMX 代理使用 Java 平台中未包含的连接器,则需要在运行 jconsole 命令时将连接器类添加到类路径中,如下所示。

$ jconsole -J-Djava.class.path=JAVA_HOME/lib/jconsole.jar:JAVA_HOME/lib/tools.jar:connector-path

In the command above, connector-path is the directory or the Java archive (Jar) file containing the connector classes that are not included in the JDK, that are to be used by JConsole.在上面的命令中, connector-path是包含连接器类的目录或 Java 归档 (Jar) 文件,这些连接器类未包含在 JDK 中,将由 JConsole 使用。

In your case, then, the command would be:那么,在您的情况下,命令将是:

$ jconsole -J-Djava.class.path=%JAVA_HOME%\\lib\\jconsole.jar;%JAVA_HOME%/lib/tools.jar:path_to_newjar_\\newjar.jar

When you leave off the JAVA_HOME/lib/tools.jar , local processes are no longer available.当您离开JAVA_HOME/lib/tools.jar ,本地进程将不再可用。

Windows 中的解决方案是在类路径上使用引号,例如:

jconsole -J-Djava.class.path="%JAVA_HOME%\\lib\\jconsole.jar;path_to_newjar_\\newjar.jar"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM