gpt4 book ai didi

java - 编译时出现 fatal error : invalid target release: 9

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:31:19 24 4
gpt4 key购买 nike

我在 Eclipse 中使用 Spring Dashboard 创建项目。我也尝试过使用 Spring Initializr 创建它并尝试了 java 的版本 8 和 9,但我仍然明白这一点。还尝试更改 Maven 目标。运行配置,maven构建使用的是JavaSE1.8,jre 1.8.0。

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RC2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>9</java.version>
</properties>

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

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

命令:

javac version: 9.0.4

Apache Maven 3.5.2
Maven home: C:\Users\arito\Desktop\apache-maven-3.5.2\bin\..
Java version: 1.8.0_152, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.8.0_152\jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

最佳答案

我不得不使用 java 9 而不是 8。

我在 MacOS 中切换了 java 环境:

列出已安装的 java 版本:/usr/libexec/java_home -V

切换到 java 9:export JAVA_HOME=`/usr/libexec/java_home -v 9.0.4`

(我之前安装了java 9)

来源:How to set JAVA_HOME environment variable on Mac OS X 10.9?

关于java - 编译时出现 fatal error : invalid target release: 9,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48950881/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com