首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Maven不使用Java 11:错误消息“致命错误编译:无效目标发布: 11”

Maven不使用Java 11:错误消息“致命错误编译:无效目标发布: 11”
EN

Stack Overflow用户
提问于 2020-07-29 13:31:46
回答 10查看 186.4K关注 0票数 85

我正在尝试用Java 11编译我的项目。

当我尝试在pom.xml中使用Java 8作为Java版本运行应用程序时,它工作得很好。但是当我尝试用Java 11运行它时,它会抛出一个错误。

致命错误编译:无效的目标发布: 11

我试图通过各种方法修复它,比如更改环境变量、更新路径以及将%JAVA_HOME%指向Java11。

命令及其在我的计算机上的结果如下:

代码语言:javascript
复制
java -version
echo %JAVA_HOME%

输出:

代码语言:javascript
复制
java version "11.0.8" 2020-07-14 LTS
C:\Program Files\Java\jdk-11.0.8

我正在使用IntelliJ理念,并按照本教程中的建议进行了必要的更改。

我的pom.xml文件如下所示:

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.0.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <name>demo</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>11</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>com.google.cloud.tools</groupId>
                <artifactId>appengine-maven-plugin</artifactId>
                <version>2.2.0</version>
                <configuration>
                    <version>1</version>
                    <projectId>businessapplication-6963d</projectId>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <source>11</source>
                    <target>11</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

当我检查Maven版本时,它将JDK1.8显示为Java版本:

代码语言:javascript
复制
mvn --version

输出:

代码语言:javascript
复制
Java version: 1.8.0_241, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk1.8.0_241\jre

如何将Maven指向Java 11?或者,如果这不是问题,如何解决这个问题?我不认为这个问题是无效目标发布: 1.7的重复,因为我已经实现了该线程中提供的解决方案。

生成项目后出错:

代码语言:javascript
复制
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.0:compile (default-compile) on project demo: Fatal error compiling: invalid target release: 11 -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

path环境变量是:

代码语言:javascript
复制
C:\Program Files (x86)\Common Files\Intel\Shared Files\cpp\bin\Intel64;
C:\Program Files (x86)\Intel\iCLS Client\;
C:\Program Files\Intel\iCLS Client\;
C:\WINDOWS\system32;C:\WINDOWS;
C:\WINDOWS\System32\Wbem;
C:\WINDOWS\System32\WindowsPowerShell\v1.0\;
C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;
C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;
C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;
C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\WINDOWS\System32\OpenSSH\;
C:\Delhi 2.0\apache-maven-3.6.1\bin;
C:\Program Files\Java\jdk-11.0.8\bin;C:\Program Files\Intel\WiFi\bin\;
C:\Program Files\Common Files\Intel\WirelessCommon\;
C:\Program Files\Git\cmd;D:\Flutter\flutter\flutter\bin;
C:\Users\Infinity97\AppData\Local\Google\Cloud SDK\google-cloud-sdk\bin;
C:\Users\Infinity97\AppData\Local\Microsoft\WindowsApps;
C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2019.2\bin;
H:\apache-maven-3.6.3\bin;
C:\Program Files\PostgreSQL\12\bin;
C:\Program Files\PostgreSQL\12\lib;
C:\Program Files\Docker Toolbox
EN

回答 10

Stack Overflow用户

回答已采纳

发布于 2020-07-29 14:15:17

似乎您的JAVA_HOME设置在您的mvn.bat中。它可能指向较早版本的Java (例如,在您的示例中为8)。

set JAVA_HOME=C:\path\to\jdk11。在调用Maven之前,尝试在第一行使用它。

票数 93
EN

Stack Overflow用户

发布于 2020-12-26 13:10:58

我在尝试将Spring Boot应用程序部署到赫鲁库时遇到了这个问题。

我的JAVA_HOME设置正确,但我仍然收到相同的错误。

但这件事对我有效:

在您的pom.xml文件中,添加或适应您自己的上下文:

代码语言:javascript
复制
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <source>1.8</source>
        <target>1.8</target>
    </configuration>
</plugin>
票数 20
EN

Stack Overflow用户

发布于 2021-03-25 20:39:26

如果其他人也有同样的问题,但是使用月食 (我知道OP指的是IntelliJ的想法),也可以检查Maven正在使用的JRE:

  • 运行配置..。
  • 选择Maven构建配置
  • 单击JRE选项卡,并根据您的POM文件选择JRE版本。
票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63154787

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档