繁体   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