我使用的是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.

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


当前回答

默认情况下,maven项目中没有设置“项目字节码版本”。

它认为你当前的版本是5。

解决方案1:

点击“项目设置>构建,执行…”>编译器>java编译器”,然后将字节码版本更改为当前java版本。

解决方案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>

其他回答

我将以下代码添加到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>

伙计们,在对这个问题进行了大量研究之后,我也遇到了这个问题,我找到了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编译器的目标字节版本中写入您的版本 在这里输入图像描述

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

您需要设置语言级别,发布版本,并将maven编译器插件添加到pom.xml

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

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

你应该用下面的方法做更多的改变:


1通过IntelliJ GUI

正如“tataelm”所提到的:

项目结构>项目设置>模块>语言级别:>然后更改为您喜欢的语言级别


2直接编辑IntelliJ配置文件

打开<ProjectName>. exe文件。iml文件(如果你使用IntelliJ,它会自动创建在你的项目文件夹中)直接通过编辑下面的行,

<组件名称="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5">

到:<组件名称="NewModuleRootManager" LANGUAGE_LEVEL="JDK_11">

因为你的方法也意味着编辑这个文件。:)


方法1实际上是要求IntelliJ帮助编辑.iml文件,而不是由您直接编辑。

我做了上面所有的事情,但必须在IntelliJ中再做一件事:

>模块

我不得不改变每个模块的“语言级别”