Windows 上的 Java 堆栈跟踪
我需要获取在使用 Windows 的客户端计算机上运行的 JVM 进程的堆栈跟踪。
客户端安装了JRE,但没有安装JDK。
我想使用 JStack,但它尚未安装,并且我们无法在客户端计算机上安装 JDK。 我还尝试使用 Java Webstart 会话中的 AdaptJ 堆栈跟踪产品,但这不起作用,因为我们远程登录并收到错误,提示不是以指定 PID 启动应用程序的会话。
本质上我想要一种在不安装 JDK 的情况下安装 JStack 的方法。
I need to get a stack trace for a JVM process running on a client machine that uses windows.
The client has the JRE installed but not the JDK.
I want to use JStack but it is not installed and we can't install a JDK on the client's machine. I also tried using AdaptJ stack trace product from a Java Webstart Session but that didn't work because we remote in and get an error about not being the session that started the application at a specified PID.
Essentially I want a way to install JStack without installing the JDK.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您可能想使用 SendSignal,它正是为此目的而设计的。
You probably want to use SendSignal, which was designed for exactly this purpose.
无论“安装”与否,JDK 和相关工具都可以正常工作,如果您只是将其压缩并解压到临时目录,您应该能够运行 jstack。 (无需修改 PATH 或 JAVA_HOME)。 只需确保您使用的版本与客户端运行应用程序的 JRE 对应即可。 至少在 JConsole 的情况下,如果版本不同,似乎会大惊小怪。 我不确定 jstack 的行为是否相同。
我并不是说这是理想的解决方案,只是说它会起作用。 我认为 jdigital 和 Eddie 的建议是更好的第一选择,尽管这不会像运行安装程序那样干扰现有的 java 安装,但客户可能会不同意。
The JDK and associated tools work fine whether "installed" or not, if you just zip up and extract it to a temporary directory, you should be able to run jstack. (No PATH or JAVA_HOME modifications necessary). Just make sure you use the same version that corresponds to the JRE your client has the application running with. At least in the case of JConsole, it seems to fuss if the versions are different. I'm not sure if jstack behaves the same way.
I'm not saying this is the ideal solution, just that it would work. I think jdigital and Eddie's suggestions are better first bets, and even though this shouldn't interfere with an existing java installation the same way running the installer would, the customer may disagree regardless.
jstack和jps是JDK的tools.jar的一部分。
此外,还需要 Attach.dll 将 jstack 附加到进程。
当然tools.jar和attach.dll不是JRE的一部分。
为了让 jstack 在没有 JDK 的系统(主要是 Windows)上工作,我通常执行以下操作。
在目标系统上。 示例:到 c:\temp\jstack
例如,创建一个bat文件jstack.bat:
对于jps类似,创建一个包含以下内容的jps.bat。
set JRE=c:\jrefolder
用法:
希望这会有所帮助。
jstack and jps are part of tools.jar of the JDK.
Also attach.dll is required to attach jstack to a process.
Ofcourse the tools.jar and attach.dll are not part of JRE.
To make jstack work on a systems which has no JDK (mostly Windows), I usually do the following.
on the target system. Example: to c:\temp\jstack
For example, create a bat file jstack.bat:
Similarly for jps, create a jps.bat with following content.
set JRE=c:\jrefolder
Usage:
Hope this helps.
您可以通过以下方式使用 JConsole远程访问?
Would you be able to use JConsole via remote access?
要仅使用 JRE 获取线程转储,您需要来自同一 Java 版本的 JDK 的 tools.jar 和 Attach.dll。 将其安装到某处并将它们复制到 jre 中。 必须是同一个版本!
如果您需要在系统帐户下运行的进程的转储,您可以使用 Windows sysinternals psexec.exe 来访问该进程。 将其复制到 JRE bin 或路径中的某个位置。
此批处理文件将堆栈转储写入具有日期时间文件名的文件,以便可以轻松获取和比较多个跟踪。
线程.bat
To get a thread dump with only a JRE you need tools.jar and attach.dll from the JDK of the same Java version. Install this somewhere and copy these into the jre. Must be identical version!
If you need a dump of a process running under the system account you can use the Windows sysinternals psexec.exe to gain access to the process. Copy this into the JRE bin or somewhere in the path.
This batch file writes the stack dump to a file with a datetime filename so multiple traces can be taken and compared easily.
Threads.bat
如果您想使用 JDK 的板载工具,并且还希望既具有最小(即不包括复制整个 JDK)又方便(即不使用自定义
.bat
调用)解决方案,这对我有用(在 Java 1.8 上尝试过):创建一个空文件夹(下面的
$DEST
)并将以下文件(从 JDK$JDK_HOME
)复制到 < code>bin 和lib
文件夹如下:然后 ZIP 并将其复制到运行兼容 JRE 的目标计算机。
您现在应该能够从
bin
文件夹运行jps
和jstack
,就像从原始 JDK 运行它们一样。If you want to use the on-board tools of the JDK and also want to both have a minimal (i.e., not including copying the whole JDK) and convenient (i.e. not invoking with a custom
.bat
) solution, this works for me (tried on Java 1.8):Create an empty folder (
$DEST
below) and copy the following files (from the JDK$JDK_HOME
) intobin
andlib
folders as follows:Then ZIP and copy this over to the destination machine running a compatible JRE.
You should be able to run
jps
andjstack
from thebin
folder now as you would run them from the original JDK.