无法使用jhat,jps,jstack调试Java Windows服务 [英] Can't debug Java Windows Services with jhat, jps, jstack

查看:608
本文介绍了无法使用jhat,jps,jstack调试Java Windows服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常展示jhat, jps 和jstack工具设置为Linux和Mac上的开发人员。但是,一位开发人员最近表示,如果有问题的Java应用程序以 Windows服务

I frequently showcase the jhat, jps, and jstack tool set to developers on Linux and Mac. However, a developer recently indicated that these are unusable in Windows if the Java app in question is running as a Windows Service.

A Sun提交的bug说的非常相似,但由于不活动而被关闭。

A Sun-filed bug says something very similar, but was closed due to inactivity.

I我已经为自己测试了这一点,但事实上它似乎是真的,尽管我几乎无法相信。以下是设置:

I have tested this out for myself, and indeed it appears true, though I can hardly believe it. Here is the setup:


  1. 使用登录为==本地系统作为Windows服务运行的Tomcat或类似物
  1. Tomcat or similar running as a Windows service with the "Log On As" == "Local System"
  2. A user with Admin privileges logged in to the same Windows machine.
  3. Admin opens Windows Task Manager, can see java.exe running
  4. Admin opens console, types "jps", gets back a list of processes that does not include Tomcat's java service process.
  5. As a brute force attempt, get the PID of tomcat as a service from Windows Task Manager. Type jstack < pid >. Get a reply: < pid > no such process

这在Windows XP,Windows 2003 Server和Windows 7下可以重现.Java版本1.5和1.6产生了相同的结果。

This appears reproducible under Windows XP, Windows 2003 Server, and Windows 7. Java versions 1.5 and 1.6 yield the same outcome.

有没有办法从终端,即使以管理员身份登录,sudo up获取JPS和其他工具来查看java服务?

Is there a way from the terminal, even though logged in as Admin, to "sudo up" to get JPS and the other tools to see the java service?

推荐答案

要使实用程序运行,您可以使用mstsc / admin使用登录帐户连接到控制台会话(不确定它需要具有的确切权限,我的是管理员组)并使用Sysinternals psexec工具作为系统运行。以下是使用jstack.exe的示例:

To get the utilities to run, you can connect to the Console session using "mstsc /admin" using a login account (not sure exact permissions it needs to have, mine was in the Administrators group) and use the Sysinternals psexec tool to run as system. Here is an example of using jstack.exe:

psexec -s "%JAVA_HOME%\bin\jstack.exe" PID >stack.txt

其中PID是流程的进程ID。您可能还必须根据具体环境将实际路径替换为JDK。

Where PID is the process ID of your process. You may also have to substitute the actual path to your JDK depending upon your specific environment.

此外,必须正确设置TEMP目录或再次使用工具。

Also, the TEMP directory must be set correctly or once again the tools will not work.

这篇关于无法使用jhat,jps,jstack调试Java Windows服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆