6

I see the org.sun.management in JRE System library but I am unable to import in my eclipse. Any reasons why it is allowed. even maven compilation fails

here are the screenshots.

enter image description here

enter image description here

I am using Java 8.

I am trying to do this:

if (operatingSystemBean  instanceof com.sun.mananagement.OperatingSystemMXBean) {


        })
brain storm
  • 30,124
  • 69
  • 225
  • 393

2 Answers2

9

Eclipse is preventing you from accessing Sun's proprietary implementation details as that won't be portable across other JVMs.

You can change the project settings so that Eclipse will treat that type of issue as a warning rather than as an error.

My steps for Latest Eclipse on Mac:

Project - Properties -> Java Compiler -> Errors / Warnings -> Enable Project specific settings -> Deprecated and restricted API -> Forbidden reference : Warning

Stephen Souness
  • 272
  • 1
  • 3
  • It is not deprecated error. It is compilation error. even Maven compilation fails (not using eclipse) – brain storm Sep 16 '15 at 21:58
  • 1
    My Eclipse setup showed the problem as "Access restriction: The type 'OperatingSystemMXBean' is not API (restriction on required library '..../jre/lib/rt.jar'" – Stephen Souness Sep 16 '15 at 22:02
  • 1
    I've created a pom.xml for my toy project that includes the relevant import and maven compilation succeeded. What does mvn -version output for you? – Stephen Souness Sep 16 '15 at 22:23
  • `Apache Maven 3.3.1 (cab6659f9874fa96462afef40fcf6bc033d58c1c; 2015-03-13T13:10:27-07:00) Maven home: /usr/local/apache-maven-3.3.1 Java version: 1.8.0_45, vendor: Oracle Corporation Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre Default locale: en_US, platform encoding: UTF-8 OS name: "mac os x", version: "10.10.4", arch: "x86_64", family: "mac"` – brain storm Sep 16 '15 at 22:27
  • 1
    My Maven setup looks quite similar, so not sure whether that is significant, but anyway. Apache Maven 3.3.3 (7994120775791599e205a5524ec3e0dfe41d4a06; 2015-04-22T12:57:37+01:00) Maven home: /usr/local/Cellar/maven/3.3.3/libexec Java version: 1.8.0_60, vendor: Oracle Corporation Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre Default locale: en_US, platform encoding: UTF-8 OS name: "mac os x", version: "10.10.5", arch: "x86_64", family: "mac" – Stephen Souness Sep 16 '15 at 22:46
  • As far as I know, Maven uses the Eclipse compiler, so that’s perfectly in line. Besides that, it makes a difference how you configure your build path. When you point to an “Execution Environment”, it bears the information about the official API, when you just point to a JRE library, all `public` classes are available… – Holger Sep 17 '15 at 08:01
-1

I've just noticed a typo in the instanceof check in your code

mananagement - should be management

Stephen Souness
  • 272
  • 1
  • 3