Visual Studio代码Java访问限制

时间:2016-11-14 22:38:51

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

我从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')

这就是它的样子:

enter image description here

如何让错误消失?正如您所看到的,如果类属于该jar文件,则会强调所有内容为红色。

1 个答案:

答案 0 :(得分:0)

如果使用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