【问题标题】:sun.jvmstat.monitor.* is not accessible in Java 11sun.jvmstat.monitor.* 在 Java 11 中不可访问
【发布时间】:2019-09-27 01:24:59
【问题描述】:

为了获取当前进程 pid,我的项目在 STS4 中使用了库 sun.jvmstat.monitor.MonitoredHost。但是,STS4 无法链接这个库,我也无法编译我的 spring boot 项目。

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) {

    }
}

这就是我拥有的所有代码。

错误:

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

使用的openJDK版本是:

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

【问题讨论】:

  • 欢迎来到 SO,请将异常添加为问题的一部分,而不是图像。还请分享 SO 成员可以尝试帮助您的最低代码示例。
  • 其实没有任何异常或错误。我只是导入 sun.jvmstat.monitor.MonitoredHost;但 STS4 无法使用 import sun.jvmstat.monitor.XXX 进行编译。
  • 这就是我写的代码。 ;(
  • 我目前用的是STS4 spring.io/tools
  • 好的,尝试添加--add-export=jdk.internal.jvmstat/sun.jvmstat.monitor=ALL-UNNAMED作为编译器选项并试一试

标签: java


【解决方案1】:
  1. 在 Eclipse/STS3-4 版本中解决 感谢this 的帖子,我能够在 eclipse 和 STS 中进行更改。

    1. 转到项目>属性:Java 构建路径,选项卡
    2. 选择 JRE > Is modules 节点并点击 Edit...
    3. 转到标签详细信息
    4. 添加的导出部分点击添加...
    5. 输入以下内容:
      • 源模块: jdk.internal.jvmstat
      • 包裹: sun.jvmstat.monitor

  1. 在 IntelliJ 想法中解决

修改文件.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>

自动解析会提示上述文件修改为

这将解决idea ide的问题。

  1. 如果您希望它添加到构建工具中,例如 mavengradle 然后

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

【讨论】:

    猜你喜欢
    • 2020-01-29
    • 1970-01-01
    • 2018-04-01
    • 1970-01-01
    • 2015-11-07
    • 1970-01-01
    • 1970-01-01
    • 2020-06-11
    相关资源
    最近更新 更多