1

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

dkb
  • 4,389
  • 4
  • 36
  • 54
dwarf.han
  • 31
  • 1
  • 7
  • Welcome to SO, please add exception as part of a question and not as an image. Also please share minimum code sample which SO member can try and help you with. – dkb May 09 '19 at 08:48
  • Actually, there is no any exception or error. I just import sun.jvmstat.monitor.MonitoredHost; but STS4 can't compile with import sun.jvmstat.monitor.XXX. – dwarf.han May 09 '19 at 08:52
  • that's what I write code. ;( – dwarf.han May 09 '19 at 08:56
  • I currently used STS4 https://spring.io/tools – dwarf.han May 09 '19 at 09:00
  • okay try adding `--add-export=jdk.internal.jvmstat/sun.jvmstat.monitor=ALL-UNNAMED` as compiler options and give a try – dkb May 09 '19 at 09:04
  • do you mean add your option when I run my executable jar? or add optoin in STS4 – dwarf.han May 09 '19 at 09:09
  • like this `javac --add-exports jdk.internal.jvmstat/sun.jvmstat.monitor=ALL-UNNAMED .java` – dkb May 09 '19 at 09:12
  • to make above changes permanent add above line as shown here https://stackoverflow.com/a/54071487/2987755 – dkb May 09 '19 at 09:39

1 Answers1

2
  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

dkb
  • 4,389
  • 4
  • 36
  • 54