Hi,
I am freshly using your extension with vs code for a new java project. The project itself had been generated via maven command line tool. The extension itself works, but i cannot get rid of this (and similar) warnings:
[Java] Access restriction: The type 'Endpoint' is not API (restriction on required library '/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/rt.jar')
I tried to set java.home to a custom jdk but it either didn't worked or the java.home setting maybe got ignored. At least the warnings persits and point always to the same jdk. It never used the path of my custom jdk.
Any help would be great
Thanks in advance
mmm I can't reproduce the warning on Mac. @snjeza can you check on linux?
As for the changing java.home, I've noticed some weird behavior too, on Mac. It seems jdt.ls initializes a JVM environment which not necessarily matches the JDK version used to run the server, but uses some Java version automatically found by Eclipse on the platform. I think we can consider that a bug in itself (Java environment should match passed java.home value)
Hi, thanks for the reply. I agree with your consideration.
BTW: The error even occured at a time when i definitly had just on jdk installed at all. The java.home problem was a followup after it started trying to use a different jdk
I will test i with a blank java project (without any maven, just to sort out that this might be the problem)
Hi, one more feedback. I cloned my project and removed everything relevant to maven (pom.xml, .settings-folder, .classpath and .project file) and the strange warning went away. Can it be, that the maven files somehow interfere with your extensions settings?
The maven project I use had been created with this command:
mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
As I also started using maven there might be an mistake on my side too
I don't know what caused the warning. We need to be able to reproduce the issue. See if you see anything relevant in the server log.
Oh man... i'm going to hit myself. I found the problem.
The maven command above created a .settings folder with a file org.eclipse.jdt.core.prefs
This file contains a setting named: org.eclipse.jdt.core.compiler.problem.forbiddenReference that was set to "warning" and caused... well, the warning. So your language server somehow fetched this setting and used it. Maybe this should get documented alongside with the other options that are available for settings.json
best regards
I see now :-)
The .settings\org.eclipse.jdt.core.prefs file is actually created by vscode-java. org.eclipse.jdt.core.compiler.problem.forbiddenReference is actually a very important setting to keep.
Basically, your issue is the Maven project uses the default maven-compiler settings where the default source setting is 1.5 and the default target setting is 1.5, independently of the JDK you run Maven with. But your JDK 8 leaks new APIs. That means if your app was really supposed to run on Java 1.5, it'd fail because it was compiled with references to Endpoint and WebMethod from 1.8, but those don't exist in 1.5.
You should modify your pom.xm to target Java 1.8 and then make sure you update the project configuration.
Great! Thanks for the quick support!!
I set org.eclipse.jdt.core.compiler.problem.forbiddenReference = ignore which is in org.eclipse.jdt.core.prefs file
it fixed.
Hey,
I'm having the same issue here with a spring project even after adding org.eclipse.jdt.core.compiler.problem.forbiddenReference = ignore
Code insider version: 1.32.0-insider (1.32.0-insider) 11416de365a1e96302e171c9eebc2547872ac230
Marketplace Version: 0.39.0
org.eclipse.buildship.core.prefs content:
connection.project.dir=
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.problem.forbiddenReference=ignore
To reproduce:
import static java.lang.management.ManagementFactory.getOperatingSystemMXBean;public int getMemorySize() {
com.sun.management.OperatingSystemMXBean os = (com.sun.management.OperatingSystemMXBean) getOperatingSystemMXBean();
return new Long(os.getTotalPhysicalMemorySize()).intValue();
}
This should result in the error message:
Access restriction: The type 'OperatingSystemMXBean' is not API (restriction on required library '/Library/Java/JavaVirtualMachines/jdk1.8.0_162.jdk/Contents/Home/jre/lib/rt.jar')
PS: This problem disappears when creating a java project and adding the line org.eclipse.jdt.core.compiler.problem.forbiddenReference=ignore to org.eclipse.buildship.core.prefs file
@Zied-Guesmi you need to put the pref in .settings\org.eclipse.jdt.core.prefs, not .settingsorg.eclipse.buildship.core.prefs
@fbricon thank you and sorry for not paying attention to that detail.
I noticed that in a java project the file created by default is .settings\org.eclipse.jdt.core.prefs but in a spring project .settingsorg.eclipse.buildship.core.prefs is created instead. shouldn't it be the same for both cases? Shouldn't the correct file be generated by default?
Most helpful comment
I set org.eclipse.jdt.core.compiler.problem.forbiddenReference = ignore which is in org.eclipse.jdt.core.prefs file
it fixed.