VirtualMachine.list()返回空列表 [英] VirtualMachine.list() returns empty list

查看:285
本文介绍了VirtualMachine.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许可协议不允许
  • 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, because tools.jar has platform-specific parts, and it depends on a native library (libattach.so) which is also missing in JRE.

因此,有以下选项:

  1. 在运行应用程序之前需要安装JDK.
  2. 将整个JDK与您的应用程序捆绑在一起.
  3. 从头开始实现缺少的功能.如果您正在寻找如何在不使用tools.jar的情况下列出正在运行的JVM,请此答案可能会给您一个想法.
  1. Require installing JDK before running your application.
  2. Bundle the entire JDK along with your application.
  3. 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屋!

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