为什么对于OperatingSystemMxBean

为什么对于OperatingSystemMxBean

本文介绍了为什么对于OperatingSystemMxBean,访问限制为jre6 / lib / rt.jar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Eclipse中编译的一些Java代码遇到一些麻烦。我一直收到以下警告......

I'm having a little trouble with some Java code I'm trying to compile in Eclipse. I keep getting the following warning...

Access restriction: The type OperatingSystemMXBean is not accessible due to restriction on required library C:\Program Files\Java\jre6\lib\rt.jar

从这一行代码...

com.sun.management.OperatingSystemMXBean bean = (com.sun.management.OperatingSystemMXBean) java.lang.management.ManagementFactory.getOperatingSystemMXBean();

我已经找到解决方法,但我担心限制警告。此代码适用于我的开源项目(),如果我'我不想解决此限制我将破坏某种许可协议。任何人都可以帮我理解这个吗?

I've found ways around this but I'm worried about the restriction warning. This code is for my open source project (CfTracker) and I don't want to work around this restriction if I'm going to be breaking some sort of license agreement. Can anyone help me understand this?

推荐答案

这不是许可协议的问题。只是Eclipse试图保护您不使用不属于官方JDK API的类(而是Oracle / Sun的JVM实现的一部分)。

This is not a problem of license agreements. It is just Eclipse trying to protect you from using classes that are not part of the official JDK API (but rather, part of Oracle/Sun's JVM implementation).

是否存在你需要进行类强制转换的一个特殊原因(而不是使用)?

Is there a particular reason that you need to class cast (rather than using the "official" interface java.lang.management.OperatingSystemMXBean)?

如果要确保在预期的MXBean不可用时继续运行应用程序,可以添加一些try / catch逻辑来优雅地处理ClassCastException。

If you want to make sure that your application continues to run when the expected MXBean is not available, you could add some try/catch logic to gracefully handle a ClassCastException.

这篇关于为什么对于OperatingSystemMxBean,访问限制为jre6 / lib / rt.jar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 00:40