【问题标题】:`mvn package` giving Fatal error compiling: invalid flag: -parameters error`mvn package` 给出致命错误编译:无效标志:-parameters 错误
【发布时间】:2019-10-30 22:08:33
【问题描述】:

我已经使用 Initialzr 工具生成了一个 Spring Boot 项目。我已经按照本教程的要求添加了模板和控制器:

https://www.baeldung.com/spring-boot-start

现在我只是尝试运行mvn clean package,但只是在我的命令提示符中看到以下错误:

...
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.501 s
[INFO] Finished at: 2019-06-17T11:03:12+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project myapp: Fatal error compiling: invalid flag: -parameters -> [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

我已经尝试在这里搜索一些错误,因为通常我可以解决这些问题,但这里没有任何信息让我无法掌握。

下面是我的 pom.xml 文件也包含了问题所在:

<?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 http://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.1.5.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>myapp</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>My App</name>

    <properties>
        <java.version>1.8</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-web</artifactId>
        </dependency>

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

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

</project>

【问题讨论】:

  • 使用mvnw clean package。这将使用 Spring Boot 附带的 maven 包装器。从您的堆栈跟踪来看,您在本地有一个较旧的 maven 版本,然后下载并与包装器一起使用。

标签: java maven spring-boot


【解决方案1】:

就我而言,我是这样做的:

  1. 在 pom.xml 中添加了以下几行:
    <properties>
        <java.version>1.8</java.version>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
  1. 转到项目的属性 -> Java 构建路径 -> 库
  2. 检查“JRE 系统库[]”是否使用“JavaSE-1.8 (jre1.8.0_221) 作为 JRE。
  3. 已选择“JRE 系统库” -> 点击“编辑...”
  4. 勾选“Alternate JRE:”选项并选择“jdk1.8.0_221”。
  5. 保存所有内容,在项目中执行“Maven Clean”并在项目中安装 Maven。

Eclipse下载Maven的仓库后,构建成功。

【讨论】:

    【解决方案2】:

    对我来说,问题在于 maven 使用的 Java 版本与项目不同。

    在我更改它以便 maven 和 project 都使用相同版本的 Java 之后,一切正常。

    在我的案例中,差异在于该项目使用的是 java 1.8,而 maven 使用的是 java 1.7。

    我直接更改了 java 的 maven 版本,因为我需要在 Java Home 中设置旧版本的 Java。为此,我提到了这个话题:How to set specific java version to Maven

    我希望这会有所帮助。

    【讨论】:

    • 谢谢,它在 mvn 命令运行之前工作:set JAVA_HOME=C:\correct_java_path
    猜你喜欢
    • 2018-02-17
    • 2018-08-12
    • 2015-06-14
    • 2021-08-09
    • 2018-08-03
    • 2015-06-01
    • 2014-02-15
    • 2015-10-14
    相关资源
    最近更新 更多