redhat-developer / vscode-java

Java Language Support for Visual Studio Code
Eclipse Public License 2.0
2.07k stars 429 forks source link

java 11 issue only in vscode (no error in intellij, no error on mvn clean install) #1755

Open clembo590 opened 3 years ago

clembo590 commented 3 years ago
Environment

Vscode shows errors and it should not: steps to reproduce: -get java 11 configured

if mvn clean install does not show any errors and if intellij does not show any errors, vscode should not show any errors.

snjeza commented 3 years ago

This is an upstream issue. See https://stackoverflow.com/questions/51094274/eclipse-cant-find-xml-related-classes-after-switching-build-path-to-jdk-10/53824670#53824670 @clembo590 you can try the following patch:

diff --git a/pom.xml b/pom.xml
index 4a4b07e..c098a55 100644
--- a/pom.xml
+++ b/pom.xml
@@ -34,6 +34,12 @@
             <artifactId>dbunit</artifactId>
             <version>2.5.2</version>
             <scope>test</scope>
+            <exclusions>
+                <exclusion>
+                    <groupId>stax</groupId>
+                    <artifactId>stax-api</artifactId>
+                </exclusion>
+            </exclusions>
         </dependency>
     </dependencies>
clembo590 commented 3 years ago

@snjeza thank you for your answer, but modifying code is not an option for me.... (code is good So code should not be changed)

Is there any way to get it working in vscode as in eclipse ? (thanks for the link: it will help if I switch back to eclipse...)

For now. in the .settings/org.eclipse.jdt.core.prefs which is generated by vscode I switched org.eclipse.jdt.core.compiler.compliance to 1.8 and no more errors.... but that is not a good fix: I need java 11....

snjeza commented 3 years ago

@clembo590 you can try to add the following attributes to the JRE_CONTAINER classpath entry to:

<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
        <attributes>
            <attribute name="maven.pomderived" value="true"/>
            <attribute name="module" value="true"/> <!-- added -->
            <attribute name="limit-modules" value="java.base"/> <!-- added -->
        </attributes>
    </classpathentry>

in the .classpath file.

However, m2e will overwrite it after the project update.

thanks for the link: it will help if I switch back to eclipse...

It works in the same way in eclipse.