VirtualMachine.list()返回空列表 [英] VirtualMachine.list() returns empty list
问题描述
当我调用VirtualMachine.list()时,当我在Eclipse上并使用jdk时,它工作正常.但是,一旦我更改为jre,或者我在eclipse中尝试了我的应用程序,此方法似乎每次都会返回一个空列表.我需要能够在仅JRE的任何地方运行我的应用程序.
When i call VirtualMachine.list(), it works fine when i'm on eclipse and with jdk. But as soon as i change to jre, or the i try my app out of eclipse, this method seems to return an empty list each time. I need to be able to run my application anywhere wih just a JRE.
for(VirtualMachineDescriptor jvm : VirtualMachine.list()){
System.out.println("jvm: " + jvm.displayName());
}
推荐答案
我需要能够在仅JRE的任何地方运行我的应用程序.
I need to be able to run my application anywhere wih just a JRE.
在这种情况下,您不应使用com.sun.tools.attach.VirtualMachine
类,因为VirtualMachine
只是JDK的一部分,而不是JRE.
In this case you should not use com.sun.tools.attach.VirtualMachine
class, since VirtualMachine
is only a part of JDK, not JRE.
- Oracle license agreement does not allow to distribute tools.jar with your application without distributing the entire JDK.
- Even if you include
tools.jar
in your application, you still won't be able to run it on any JRE, becausetools.jar
has platform-specific parts, and it depends on a native library (libattach.so) which is also missing in JRE.
因此,有以下选项:
- 在运行应用程序之前需要安装JDK.
- 将整个JDK与您的应用程序捆绑在一起.
- 从头开始实现缺少的功能.如果您正在寻找如何在不使用
tools.jar
的情况下列出正在运行的JVM,请此答案可能会给您一个想法.
- Require installing JDK before running your application.
- Bundle the entire JDK along with your application.
- Implement the missing functionality from scratch. If you are looking how to list running JVMs without using
tools.jar
, this answer might give you an idea.
这篇关于VirtualMachine.list()返回空列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!