我使用的是IntelliJ IDEA Ultimate 2019.3.1。每当我尝试启动任何简单的Java Maven项目(可能它甚至是一个简单的Hello World),我得到以下错误:

Error:java: error: release version 5 not supported

运行java——version by terminal得到如下输出:

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 by terminal得到如下输出:

javac 11.0.5

转到Java编译器的设置(在这里建议),我看到这个:

我尝试将“目标字节码版本”编辑为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

将其更改为1.11版本,我得到这个错误:

Error:java: Source option 5 is no longer supported. Use 6 or later.

你认为是什么问题?我该怎么解决呢?


当前回答

又找到了一个可以换衣服的地方,这对我来说很好。

Project Structure -> < Select Module > Dependencies -> Module SDK < Select version from drop down >

其他回答

您只需在pom.xml中添加这两行。在那之后,你的问题就解决了。

<!--pom.xml-->
<properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
</properties>

见https://stackoverflow.com/a/12900859/104891。

首先,像这样在pom.xml中设置语言级别/发布版本:

<properties>
  <maven.compiler.source>1.8</maven.compiler.source>
  <maven.compiler.target>1.8</maven.compiler.target>
</properties>

否则,Maven将默认值设置为1.5。你还需要包含maven-compiler-plugin(如果你还没有的话):

<dependency>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>3.8.1</version>
</dependency>

此外,尝试在以下每个地方更改Java版本:

11.文件->项目结构->项目->项目SDK ->

11.文件->项目结构->项目->项目语言级别->

11 .文件->项目结构->项目->模块-> ->来源->

11 . In project -> ctrl + alt + s -> Build, Execution, Deployment -> Compiler -> Java Compiler -> project bytecode version ->

在项目-> ctrl + alt + s ->构建,执行,部署->编译器-> Java编译器->模块-> 1.11。

在我的情况下,唯一可行的解决方案是将以下块添加到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>

这个问题的解决方案已经在一些答案中定义了。但还是需要表达一个细节。这个问题完全与maven有关,解决方案也在pom.xml配置中。IntelliJ只读取maven配置,如果配置有错误的信息,IntelliJ也会尝试使用该配置。

如大多数答案所示,要解决这个问题,只需将以下属性添加到项目的pom.xml中。

<properties> 
      <maven.compiler.source>1.8</maven.compiler.source> 
      <maven.compiler.target>1.8</maven.compiler.target> 
</properties>

之后,在IntelliJ端,重新导入maven配置。要重新导入maven配置,右键单击项目的pom.xml文件并选择reimport。IntelliJ首选项中的编译器版本相关信息将根据pom.xml中的值自动更新。

伙计们,在对这个问题进行了大量研究之后,我也遇到了这个问题,我找到了3个解决方案来解决这个问题

在pom.xml中添加这些属性;//抱歉格式化

1.8 <属性> < java.version > < / 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 > < java.version > 11 < / java.version >属性> < /

删除目标字节版本中的所有内容,您可以在IntelliJ的java编译器设置中找到这一点

删除目标字节版本以下的所有内容,使其为空

找到您在依赖项中使用的appium版本。这里我使用的是7.3.0 在pom.xml中找到您在依赖项中使用的appium的版本

然后在java编译器的目标字节版本中写入您的版本 在这里输入图像描述

喜欢代码>>>,希望它对你有用