IntelliJ:错误:java:错误:不支持发行版本5 [英] IntelliJ: Error:java: error: release version 5 not supported
问题描述
我正在使用 IntelliJ IDEA Ultimate 2019.3.1 .每当我尝试启动任何简单的Java Maven项目(甚至可能是一个简单的Hello World)时,都会出现以下错误:
I'm using IntelliJ IDEA Ultimate 2019.3.1. Whenever I try to start any simple Java Maven project (may it be even a simple Hello World) I get the following error:
Error:java: error: release version 5 not supported
通过终端运行java --version
,我得到以下输出:
Running java --version
by terminal I get the following output:
openjdk 11.0.5 2019-10-15
OpenJDK Runtime Environment (build 11.0.5+10-post-Ubuntu-0ubuntu1.1)
OpenJDK 64-Bit Server VM (build 11.0.5+10-post-Ubuntu-0ubuntu1.1, mixed mode, sharing)
通过终端运行javac --version
,我得到以下输出:
Running javac --version
by terminal I get the following output:
javac 11.0.5
转到Java编译器的设置(如建议的此处),我看到了:
Going to the Settings of the Java Compiler ( as suggested here ) I see this:
我尝试将"目标字节码版本"编辑为 1.8 ,但出现以下错误:
I tried editing the "Target bytecode version" to 1.8 but I get the following errors:
Error:(1, 26) java: package javafx.application does not exist
Error:(2, 20) java: package javafx.stage does not exist
Error:(4, 27) java: cannot find symbol
symbol: class Application
Error:(12, 23) java: cannot find symbol
symbol: class Stage
location: class Main
Error:(7, 9) java: cannot find symbol
symbol: method launch(java.lang.String[])
location: class Main
Error:(11, 5) java: method does not override or implement a method from a supertype
将其更改为版本 1.11 ,我收到此错误:
Changing it to version 1.11 I get this error instead:
Error:java: Source option 5 is no longer supported. Use 6 or later.
您认为问题出在哪里?我该怎么解决?
What do you think is the problem? How may I solve it?
推荐答案
请参见 https://stackoverflow.com/a/12900859/104891 .
首先,在pom.xml
中将language level
/release versions
设置为:
First of all, set the language level
/release versions
in pom.xml
like that:
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
否则,Maven会将默认值设置为1.5.如果还没有的话,还需要包含maven-compiler-plugin
:
Maven sets the default to 1.5 otherwise. You will also need to include the maven-compiler-plugin
if you haven't already:
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</dependency>
此外,尝试在以下每个位置更改Java版本:
Also, try to change the Java version in each of these places:
文件->项目结构->项目->项目SDK-> 11.
File -> Project structure -> Project -> Project SDK -> 11.
文件->项目结构->项目->项目语言级别-> 11.
File -> Project structure -> Project -> Project language level -> 11.
文件->项目结构->项目->模块->->源-> 11
File -> Project structure -> Project -> Modules -> -> Sources --> 11
在项目中-> ctrl + alt + s ->构建,执行,部署->编译器-> Java编译器->项目字节码版本-> 11
In project -> ctrl + alt + s -> Build, Execution, Deployment -> Compiler -> Java Compiler -> Project bytecode version -> 11
在项目中-> ctrl + alt + s ->构建,执行,部署->编译器-> Java编译器->模块-> 1.11.
In project -> ctrl + alt + s -> Build, Execution, Deployment -> Compiler -> Java Compiler -> Module -> 1.11.
这篇关于IntelliJ:错误:java:错误:不支持发行版本5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!