簡體   English   中英

“mvn spring-boot:run”出錯,[錯誤] 未能執行目標 org.apache.maven:3plugins:maven1-compiler-plugins:.10.

[英]Error with "mvn spring-boot:run", [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.10.1:compile

我正在嘗試使用命令 mvn spring-boot:run 或者當我嘗試使用命令 mvn clen install 時。 但它給了我這種錯誤:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.10.1:compile (default-compile) on project demo: Fatal error compiling: invalid target release: 17 -> [Help 1]
[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

這是我的 pom 文件:

<?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.7.3</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>qualabs</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>17</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>
        </dependency>

        <!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.9.1</version>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>

    </dependencies>

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

</project>

如果我使用應用程序中的 main 方法運行項目,它會完美運行。 我不知道這是否是依賴關系的問題

謝謝你們的幫助

嘗試執行以下命令查看你的電腦默認使用的是哪個Java版本:

java -version

如果它與您嘗試在項目中使用的 17 版本不同,您應該更新您的 JAVA_HOME 變量。

您可以使用此命令列出所有可用的 Java 版本,安裝在您的計算機上:

/usr/libexec/java_home -V

示例 output 來自我的機器:

    17.0.2 (arm64) "Oracle Corporation" - "OpenJDK 17.0.2" /Users/golovnya/Library/Java/JavaVirtualMachines/openjdk-17.0.2/Contents/Home
    11.0.14.1 (x86_64) "Amazon.com Inc." - "Amazon Corretto 11" /Users/golovnya/Library/Java/JavaVirtualMachines/corretto-11.0.14.1/Contents/Home

該命令可用於將特定 Java 版本設置為默認版本(本例中為 17):

export JAVA_HOME=$(/usr/libexec/java_home -v 17)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM