简体   繁体   English

如何找出哪个Java实例已加载类

[英]How to figure out which instance of java has a class loaded

I'm trying to figure out how a system works. 我试图弄清楚系统如何工作。 When I do a 'ps -A' I see several java processes. 当我执行“ ps -A”时,我看到了几个java进程。 Is there a way to run a command that will examine a java instance and let me know what all jars or classes are loaded from that instance (preferably without stopping the instance)? 有没有一种方法可以运行将检查Java实例并让我知道从该实例加载了所有jar或类的命令(最好不停止该实例)?

您将需要使用某些特定于Java的工具(例如VisualVM)来完成您要查询的内容。

You can use jconsole or visualvm to get the details of the running JVM. 您可以使用jconsole或visualvm获取正在运行的JVM的详细信息。 These require xwindows if you are using linux. 如果您使用的是Linux,则需要使用xwindows。

Further, jps -v will let you know what was the command line argument used to start the JVM. 此外,jps -v将使您知道用于启动JVM的命令行参数是什么。 From there you should be able to see what jars where used for the classpath. 从那里,您应该能够看到用于类路径的jar。

ps -Af

Will show you the exact command used to launch the process. 将向您显示用于启动该过程的确切命令。 It can not, however, tell you exactly which libraries that the invoked JAR file has loaded (although you do presumably get the classpath so you can make inferences). 但是,它不能确切告诉您调用的JAR文件已加载了哪些库(尽管您可能确实获得了类路径,因此可以进行推断)。

For more detail you'll need a tool that interrogates the JVM. 有关更多详细信息,您将需要询问JVM的工具。

In case of Java application server running web or enterprise (EAR) application, you cannot deduce all used jars from command line. 如果Java应用程序服务器运行Web或企业(EAR)应用程序,则无法从命令行推断所有使用过的jar。 But you can use eg lsof command to list all files that given java process is using. 但是您可以使用lsof命令列出给定java进程正在使用的所有文件。 And filter jars from them. 并从中过滤罐子。

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

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