【问题标题】:Invalid target release when compiling Java application编译 Java 应用程序时目标版本无效
【发布时间】:2022-01-11 10:36:44
【问题描述】:

当我在 IntelliJ 终端中运行 mvn clean package 时出现此错误:

[错误] 无法执行目标 org.apache.maven.plugins:maven-compiler-plugin:3.6.1:compile (default-compile) on project protection: Fatal error compile: invalid target release: 1.8 -> [帮助1] [错误] [错误] 要查看错误的完整堆栈跟踪,请使用 -e 开关重新运行 Maven。 [错误] 使用 -X 开关重新运行 Maven 以启用完整的调试日志记录。 [错误] [错误] 有关错误和可能的解决方案的更多信息,请阅读以下文章: [错误] [帮助1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

这是否告诉我它正在尝试使用 Java 1.8 进行编译,或者它需要 Java 1.8 但可用版本不正确?

【问题讨论】:

  • release 直到 9 点才可用;使用sourcetarget

标签: java maven-3


【解决方案1】:

您使用的是1.8。编译器的默认值为1.6,因此您需要将插件属性更改为:

<plugins>
 <plugin>    
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <source>1.8</source>
        <target>1.8</target>
    </configuration>
 </plugin>
</plugins>

【讨论】:

  • 你在哪里看到默认值 1.6?
  • meven 编译器插件的默认值为 1.6,您可以在此处阅读更多信息 link
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-11-19
  • 1970-01-01
  • 2015-06-16
  • 2018-08-03
  • 2015-06-01
  • 2015-06-14
  • 2015-10-14
相关资源
最近更新 更多