【问题标题】:Visual Studio Code Java Access RestrictionVisual Studio Code Java 访问限制
【发布时间】:2017-03-28 16:44:11
【问题描述】:

我从 RedHat 扩展 (https://marketplace.visualstudio.com/items?itemName=redhat.java) 安装了 Java 语言支持,但我在 JavaFX 应用程序中收到此错误。

错误:

[Java] Access restriction: The type 'Application' is not API (restriction on required library '/usr/lib/jvm/java-8-oracle/jre/lib/ext/jfxrt.jar')

它是这样的:

我怎样才能使错误消失?如您所见,如果类属于该 jar 文件,则会在红色下划线。

【问题讨论】:

  • 改变你的 jre
  • 我正在使用 openjre8。我应该使用什么?
  • 将其降级为您拥有的任何人,然后再次升级
  • 好的,我试试看。

标签: java linux ubuntu jar visual-studio-code


【解决方案1】:

如果你使用Gradle,可以使用eclipse插件将访问规则直接集成到build.gradle中:

import org.gradle.plugins.ide.eclipse.model.AccessRule

apply plugin: 'java'
apply plugin: 'eclipse'

eclipse {
    classpath {
        file {
            whenMerged {
                def jre = entries.find { it.path.contains 'org.eclipse.jdt.launching.JRE_CONTAINER' }
                jre.accessRules.add(new AccessRule('0', 'javafx/**'))
                jre.accessRules.add(new AccessRule('0', 'com/sun/javafx/**'))
            }
        }
    }
}

这对我有用。


PS 解决方案最初发布在这里:https://github.com/redhat-developer/vscode-java/issues/120

【讨论】:

  • 它也适用于我,但我仍然没有得到它。为什么会出现这个错误?
猜你喜欢
  • 2022-01-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-16
  • 1970-01-01
  • 2022-01-07
  • 1970-01-01
相关资源
最近更新 更多