The java builder should use the correct compiler compliance to build the project
See original GitHub issueEnvironment
- Operating System: MacOS and Windows 10
- JDK version: any
- Visual Studio Code version: 1.41.x or 1.42.0-insider
- Java extension version: 0.57.0
Steps To Reproduce
- Have java.home to point to JDK 13, and launch the language server.
- Have Java 8 installed in the machine.
- Configure multiple JDKs in the user setting.
"java.configuration.runtimes": [
{
"name": "JavaSE-13",
"path": "C:\\Program Files\\Java\\jdk-13.0.1"
},
{
"name": "JavaSE-1.8",
"path": "C:\\Program Files\\AdoptOpenJDK\\jdk-8.0.242.08-hotspot"
}
]
- Open an eclipse Java 8 project 26.environmentVariables.zip .
Current Result:
See the screenshot above, the PROBLEMS viewlet reports a warning on the project: “The compiler compliance specified is 13 but a JRE 1.8 is used”. This means the classfile built by the ls is targeting to java 13, that would make it not able to be launched in JDK 8.
Besides, the debugger has fixed a bug https://github.com/microsoft/vscode-java-debug/issues/753 about using the project’s Java runtime to launch the application. The latest debugger would fail at this case.
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: EnvrionmentVariable has been compiled by a more recent version of the Java Runtime (class file version 57.0), this version of the Java Runtime only recognizes class file versions up to 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:757)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:419)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
at java.lang.ClassLoader.loadClass(ClassLoader.java:352)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:495)
Expected
The language server should generate the compatible .class files with the project’s Java Runtime.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:10 (3 by maintainers)
Top Results From Across the Web
The compiler compliance specified is 1.6 but a JRE 1.8 is used
Right -click on your project and select "Properties -> Java Compiler" , check "Enable project specific settings" and select 1.5 or 1.6 from...
Read more >How to change Java compiler version for Eclipse project
To change version of Java compiler for your project, uncheck “Use compliance from execution environment…”, the you can choose Java version ...
Read more >How to force JDK 1.8 compliance in a Maven POM example
The only way to make this a permanent change is to edit the Maven compiler plugin POM entry and force Eclipse and Maven...
Read more >Java Builder - Eclipse Help
The Java builder can build programs incrementally as individual Java files are saved. Note that the Eclipse Compiler for Java can also be...
Read more >Setting the compiler compliance level - 8.0 - Talend Help Center
... task The compiler compliance level corresponds to the Java version used for Job code generation. For more information on the compiler compliance...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I had the same problem when not using the properties:
As I’m experimenting with Java 14 the way to configure the java version in maven has changed to:
Thus, from the point of view of maven, it is no longer necessary to use maven.compiler.target/source, however, for VS Code it is still necessary to specify these properties so that it correctly interprets the version of Java used in the project.
Then, I solve my scenario using this two settings above.
I have the same problem on a project with mixed JDK 8 and JDK 11/17 for its module. Seems solved by applying same solution as in https://github.com/redhat-developer/vscode-java/issues/1290#issuecomment-663330274
e.g.: not enough
but this works:
I am using