dwarf.han
dwarf.han

Reputation: 31

sun.jvmstat.monitor.* is not accessible in Java 11

to get current process pid, my project used library sun.jvmstat.monitor.MonitoredHost in STS4. However, STS4 couldn't link this library and I couldn't compile my spring boot project.

import sun.jvmstat.monitor.MonitoredHost;
import sun.jvmstat.monitor.MonitoredVm;
import sun.jvmstat.monitor.MonitoredVmUtil;
import sun.jvmstat.monitor.VmIdentifier;

public class MonitorTest {

    public static void main(String[] args) {

    }
}

That's all the code I have.

Error :

The type sun.jvmstat.monitor.MonitoredHost is not accessible
The type sun.jvmstat.monitor.MonitoredVm is not accessible
The type sun.jvmstat.monitor.MonitoredVmUtil is not accessible
The type sun.jvmstat.monitor.VmIdentifier is not accessible

used openJDK version is :

java -version
openjdk 11.0.1 2018-10-16
OpenJDK Runtime Environment 18.9 (build 11.0.1+13)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.1+13, mixed mode)

STS4 intellisense error

Upvotes: 1

Views: 3913

Answers (1)

dkb
dkb

Reputation: 4596

  1. To Solve in Eclipse/STS3-4 version Thanks to this post, I am able to do changes in eclipse and STS both.

    1. Go to Project > Properties: Java Build Path, tab Libraries
    2. Select the JRE > Is modular node and click Edit...
    3. Go to the tab Details
    4. In the Added exports section click Add...
    5. Enter the following:
      • Source module: jdk.internal.jvmstat
      • Package: sun.jvmstat.monitor

with compiler error

without compiler error

  1. To solve in IntelliJ idea

modify a file .idea/compiler.xml

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  <component name="JavacSettings">
    <option name="ADDITIONAL_OPTIONS_OVERRIDE">
      <module name="demo.main" options="--add-exports=jdk.internal.jvmstat/sun.jvmstat.monitor=ALL-UNNAMED" />
    </option>
  </component>
</project>

or

Auto-resolve will prompt for above file modification as

idea

This will solve the issue with idea ide.

  1. If you want it to add to build tools like maven or gradle then

javac --add-exports jdk.internal.jvmstat/sun.jvmstat.monitor=ALL-UNNAMED --class-path $dependencies -d $targetFolder $sourceFiles

Upvotes: 2

Related Questions