IntelliJ:错误:java:错误:不支持发布版本 5
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/59601077/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
IntelliJ: Error:java: error: release version 5 not supported
提问by Robb1
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:
我正在使用IntelliJ IDEA Ultimate 2019.3.1。每当我尝试启动任何简单的 Java Maven 项目(甚至可能是一个简单的 Hello World)时,我都会收到以下错误:
Error:java: error: release version 5 not supported
Running java --version
by terminal I get the following output:
java --version
通过终端运行我得到以下输出:
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)
Running javac --version
by terminal I get the following output:
javac --version
通过终端运行我得到以下输出:
javac 11.0.5
Going to the Settings of the Java Compiler ( as suggested here) I see this:
要在Java编译器的设置(如建议在这里)我看到这一点:
I tried editing the "Target bytecode version" to 1.8but I get the following errors:
我尝试将“目标字节码版本”编辑为1.8,但出现以下错误:
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
Changing it to version 1.11I get this error instead:
将其更改为1.11版,我收到此错误:
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?
你认为有什么问题?我该如何解决?
采纳答案by Konstantin Annikov
See?https://stackoverflow.com/a/12900859/104891.
看?https://stackoverflow.com/a/12900859/104891。
First of all, set the language level
/release versions
in pom.xml
like that:
首先,设置language level
/release versions
在pom.xml
这样的:
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
Maven sets the default to 1.5 otherwise. You will also need to include the maven-compiler-plugin
if you haven't already:
否则,Maven 将默认值设置为 1.5。maven-compiler-plugin
如果您还没有,您还需要包括:
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</dependency>
Also, try to change the Java version in each of these places:
此外,尝试在以下每个位置更改 Java 版本:
File -> Project structure -> Project -> Project SDK -> 11.
文件 -> 项目结构 -> 项目 -> 项目 SDK -> 11.
File -> Project structure -> Project -> Project language level -> 11.
文件 -> 项目结构 -> 项目 -> 项目语言级别 -> 11。
File -> Project structure -> Project -> Modules -> -> Sources --> 11
文件 -> 项目结构 -> 项目 -> 模块 -> -> 来源 -> 11
In project -> ctrl+ alt+ s-> Build, Execution, Deployment -> Compiler -> Java Compiler -> Project bytecode version -> 11
在项目- > ctrl+ alt+ s- >构建,执行,部署- >编译器- > Java编译器- >项目的字节码版本- > 11
In project -> ctrl+ alt+ s-> Build, Execution, Deployment -> Compiler -> Java Compiler -> Module -> 1.11.
在项目- > ctrl+ alt+ s- >构建,执行,部署- >编译器- > Java编译器- >模块- > 1.11。
回答by V Jansen
If you are using spring boot as a parent, you should set the java.version property, because this will automatically set the correct versions.
如果你使用 spring boot 作为父级,你应该设置 java.version 属性,因为这会自动设置正确的版本。
<properties>
<java.version>11</java.version>
</properties>
The property defined in your own project overrides whatever is set in the parent pom. This overrides all needed properties to compile to the correct version.
在您自己的项目中定义的属性会覆盖父 pom 中设置的任何内容。这会覆盖编译到正确版本所需的所有属性。
Some information can be found here: https://www.baeldung.com/maven-java-version
一些信息可以在这里找到:https: //www.baeldung.com/maven-java-version
回答by borisveis
Took me a while to aggregate an actual solution, but here's how to get rid of this compile error.
我花了一段时间来汇总一个实际的解决方案,但这里是如何摆脱这个编译错误。
- Open Intelij preferences
- Search for "compiler (or something like "compi"
- scroll down to Maven -->java compiler. In the right panel, will be a list of modules and their associated java compile version "target bytecode version."
- Select a version >1.5. You may need to upgrade your jdk if one is not available.enter image description here
- 打开 Intelij 首选项
- 搜索“编译器(或类似“compi”的东西)
- 向下滚动到 Maven -->java 编译器。在右侧面板中,将是一个模块列表及其关联的 java 编译版本“目标字节码版本”。
- 选择版本 >1.5。如果 jdk 不可用,您可能需要升级您的 jdk。在此处输入图片说明
回答by Jéssica Machado
I add the next code to my pom.xml
file, it solved my problem.
我将下一个代码添加到我的pom.xml
文件中,它解决了我的问题。
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
回答by Mehedi Abdullah
You have to add only two linesin your pom.xmland after that your problem will be gone.
Add this two line in your pom.xml -
您只需在pom.xml 中添加两行,然后您的问题就会消失。在 pom.xml 中添加这两行 -
<!--pom.xml-->
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
回答by Ali Shah
Within IntelliJ, open pom.xml file
在 IntelliJ 中,打开 pom.xml 文件
Add this section before (If your file already has a section, just add the lines below to that existing section):
在之前添加此部分(如果您的文件已经有一个部分,只需将以下行添加到该现有部分):
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>`
回答by Sikhumbuzo Sithole
if your are using intellj got to setting => compiler change the version to ur java current version
如果您使用的是 intellj 必须设置 => 编译器将版本更改为您的 java 当前版本
回答by Muhammed Gül
The only working solution in my case was adding the following block to pom.xml
:
在我的情况下,唯一可行的解决方案是将以下块添加到pom.xml
:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version> <configuration> <release>12</release>
</configuration>
</plugin>
</plugins>
</build>
回答by Arjun Marati
By default, your "Project bytecode version isn't set in maven project.
默认情况下,您的“项目字节码版本未在 Maven 项目中设置。
It thinks that your current version is 5. Solution1: Just go to "Project Settings>Build, Execution...>compiler>java compiler" and then change your bytecode version to your current java version.
它认为您当前的版本是5。 解决方案1:只需转到“项目设置>构建,执行...>编译器>java编译器”,然后将您的字节码版本更改为您当前的java版本。
Solution2: Adding below build plugin in POM file:
解决方案2:在POM文件中添加以下构建插件:
<properties>
<java.version>1.8</java.version>
<maven.compiler.version>3.8.1</maven.compiler.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.version}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>
Have a Good Day !!
祝你有美好的一天 !!