当前位置: 首页 > 知识库问答 >
问题:

编译时发生致命错误:无效的目标版本:9

宇文嘉勋
2023-03-14

我使用Eclipse中的Spring仪表板创建项目。我也尝试过使用Spring初始化器创建它,并尝试了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"

共有3个答案

沈高峻
2023-03-14

这发生在我使用Java8而不是Java11时,所以我安装了Java11,错误消失了。

丁和歌
2023-03-14

我使用以下配置解决此问题:

<build>
    <plugins>
        <!-- target Java 9 -->
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <!-- fork compilation and use the
                         specified executable -->
                <fork>true</fork>
                <executable>javac9</executable>
            </configuration>
        </plugin>
    </plugins>
</build>

还有其他替代方法,如Maven工具链或mavenrc文件。

江宏伟
2023-03-14

致命错误编译:无效的目标释放:9(和你的一样),所以我改变了红色突出显示的字段pom.xmleclipse

 类似资料: