Maven:查看编译选项? [英] Maven: Viewing compile options?

查看:133
本文介绍了Maven:查看编译选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试追踪这个编译错误:

I'm trying to track down this compile error:

$ mvn compile
...
[ERROR] /.../Reader.java:[14,13] try-with-resources is not supported in -source 1.5
(use -source 7 or higher to enable try-with-resources)

如何找到 -source 1.5 设置在我的Maven编译中?我使用普通的 pom.xml 这个(据我所知)没有设置任何东西。

How can find the -source 1.5 setting in my Maven compilation? I'm using a plain vanilla pom.xml which (as far as I can tell) isn't setting anything.

推荐答案

这是因为您使用普通的 pom.xml 表示您遇到此问题。

This is because you are using a plain vanilla pom.xml that you have this issue.

默认情况下, maven -compiler-plugin ,在编译源代码时调用,使用Java 5进行编译,无论你设置为 $ JAVA_HOME


另请注意,目前默认的源设置为1.5,默认目标设置为1.5,与您运行Maven的JDK无关。

Also note that at present the default source setting is 1.5 and the default target setting is 1.5, independently of the JDK you run Maven with.

要使用其他编译器版本(例如Java 8),您可以设置以下属性

To use a different compiler version (e.g. Java 8), you can set the following properties:

<properties>
  <maven.compiler.source>1.8</maven.compiler.source>
  <maven.compiler.target>1.8</maven.compiler.target>
</properties>

或直接配置插件:

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

这篇关于Maven:查看编译选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆