Java 无法将 JConsole 与作为 Windows 服务运行的 Tomcat 一起使用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/503057/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unable to use JConsole with Tomcat running as windows service
提问by Kees de Kooter
I am running tomcat 6.0.18 as a windows service. In the service applet the jvm is configured default, i.e. it is using jvm.dll of the JRE.
我正在运行 tomcat 6.0.18 作为 Windows 服务。在服务小程序中,jvm 被默认配置,即它使用JRE 的jvm.dll。
I am trying to monitor this application with JConsole but cannot connect to it locally. I added the parameter -Dcom.sun.management.jmxremote (which works when starting tomcat with the start.bat script). But the jvm does not seem to pick up the parameter.
我正在尝试使用 JConsole 监视此应用程序,但无法在本地连接到它。我添加了参数 -Dcom.sun.management.jmxremote(在使用 start.bat 脚本启动 tomcat 时有效)。但是jvm好像没有接参数。
采纳答案by Ed Thomas
There's a nice GUI to edit the options, no need to muck around in the registry.
有一个很好的 GUI 来编辑选项,无需在注册表中乱搞。
Open up the C:\Program Files\Apache Software Foundation\Tomcat 6.0\bin\tomcat6.exe (or just double-click on the monitor icon in the task bar). Go to the Java pane, add the following to the list of arguments, and restart Tomcat.
打开 C:\Program Files\Apache Software Foundation\Tomcat 6.0\bin\tomcat6.exe(或者只需双击任务栏中的监视器图标)。转到 Java 窗格,将以下内容添加到参数列表中,然后重新启动 Tomcat。
-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8086 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false
Then you can connect with JConsole or the newer VisualVM.
然后您可以连接 JConsole 或更新的 VisualVM。
回答by Ron
Here's the prescribed way for changing jvmoptions & interacting with the service:
这是更改 jvmoptions 和与服务交互的规定方法:
http://tomcat.apache.org/tomcat-5.5-doc/windows-service-howto.html
http://tomcat.apache.org/tomcat-5.5-doc/windows-service-howto.html
I would try going into your registry at HKLM/Software/Apache Software Foundation/Procrun 2.0//Parameters/Java and editing the "Options" multi-string value directly.
我会尝试进入您在 HKLM/Software/Apache Software Foundation/Procrun 2.0//Parameters/Java 的注册表并直接编辑“选项”多字符串值。
回答by Ed Thomas
If Tomcat is running as a Windows service, and you want to attach to the JVM locally, you need to run VisualVM or JConsole as the System account. You can use Sysinternals PsExec.exeto accomplish this.
如果 Tomcat 作为 Windows 服务运行,并且您想在本地附加到 JVM,则需要作为系统帐户运行 VisualVM 或 JConsole。您可以使用Sysinternals PsExec.exe来完成此操作。
psexec.exe -i -s c:\visualvm\bin\visualvm.exe
回答by ripper234
I'm posting it mainly to record this information to myself, I haven't validated it - but this is supposed to work as well:
我发布它主要是为了给自己记录这些信息,我还没有验证它 - 但这应该也有效:
http://mysqlandsqlserver.blogspot.com/2010/02/jconsolejmap-and-tomcat-as-windows.html
http://mysqlandsqlserver.blogspot.com/2010/02/jconsolejmap-and-tomcat-as-windows.html
回答by Ross Attrill
Add the following near the top of your catalina.bat
在 catalina.bat 顶部附近添加以下内容
set JAVA_OPTS=%JAVA_OPTS% -Dcom.sun.management.jmxremote ^
-Dcom.sun.management.jmxremote.port=8086 ^
-Dcom.sun.management.jmxremote.ssl=false ^
-Dcom.sun.management.jmxremote.authenticate=false
Stop and restart tomcat (obviously)
停止并重新启动tomcat(显然)
Run jconsole.exe. If your tomcat is running as service, then run jconsole.exe as administrator.
运行 jconsole.exe。如果您的 tomcat 作为服务运行,则以管理员身份运行 jconsole.exe。
Select Remote Process and enter localhost:8086
选择远程进程并输入 localhost:8086
回答by Andrei
There is still a rather simple way to connect JConsole to Java process started as Windows Service using the local mode which I discovered here.
仍然有一种相当简单的方法可以使用我在此处发现的本地模式将 JConsole 连接到作为 Windows 服务启动的 Java 进程。
Basically it says that in order to connect to Java process launched as a Windows Service you need to launch JConsole as a Windows Service (you can do it using windows native api or using any wrapper like yajsw.)
基本上它说为了连接到作为 Windows 服务启动的 Java 进程,您需要将 JConsole 作为 Windows 服务启动(您可以使用 Windows 本机 api 或使用任何包装器,如yajsw。)
By the way, this will free you from restarting the Java Process which was critical for me.
顺便说一句,这将使您无需重新启动对我来说至关重要的 Java 进程。