VSCode Java access restriction error that HttpServer is not API

Viewed 1561

In VSCode v1.18.0 with Redhat's Language Support for Java v0.14.0 extension, I get error notifications in the editor due to using com.sun.net.httpserver.* classes as show here

enter image description here

All red squigglies disappear when I tweak the extension created .classpath file like

...
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/">
  <accessrules>
    <accessrule kind="accessible" pattern="com/sun/net/**"/>
  </accessrules>
</classpathentry>
...

The problem is that the .classpath file appears to be overwritten whenever VSCode is restarted.

update: neither jdeps nor jdeprscan complain about the compiled jar

$ jdeps --version
9.0.1

$ jdeprscan --version
9.0.1

$ jdeps --jdk-internals ContactService-0.5.0.jar 

$ jdeprscan ContactService-0.5.0.jar
Jar file ContactService-0.5.0.jar:

Is there a way (e.g. a magic arg to the extension's java.jdt.ls.vmargs setting?) to make just these editor error notifications disappear permanently?

1 Answers

My VS Code doesn't reset the .classpath file. It could be your version?

I'm using:

Version: 1.39.2 (user setup)
Commit: 6ab598523be7a800d7f3eb4d92d7ab9a66069390
Date: 2019-10-15T15:35:18.241Z
Electron: 4.2.10
Chrome: 69.0.3497.128
Node.js: 10.11.0
V8: 6.9.427.31-electron.0
OS: Windows_NT x64 10.0.16299

If you're using gradle, you could do as suggest here: https://github.com/redhat-developer/vscode-java/issues/120#issuecomment-450530640

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/**'))
            }
        }
    }
}

Just change to your needs

Related