Maven 构建失败,如何在 Eclipse 中将 -source 1.5 更改为 -source 7 或更高版本

Maven Build failure, How to change -source 1.5 to -source 7 or higher for maven in eclipse

我在 Eclipse 中有一个 Maven 项目。在建立它的显示错误时:

--- maven-clean-plugin:2.5:clean (default-clean) @ DataMasking ---
[INFO] Deleting D:\workspaces\Datamasking\DataMasking\target
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ 
DataMasking ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered 
resources, i.e. build is platform dependent!
[INFO] Copying 22 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ DataMasking 
---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, 
i.e. build is platform dependent!
[INFO] Compiling 78 source files to 
D:\workspaces\Datamasking\DataMasking\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR]/D:/workspaces/Datamasking/DataMasking/src/main/java/com/medicare/mask/dao/ApplicationDao.java:[197,21] try-with-resources is not supported in -source 1.5
 (use -source 7 or higher to enable try-with-resources)
[ERROR] /D:/workspaces/Datamasking/DataMasking/src/main/java/main.java:[60,21] try-with-resources is not supported in -source 1.5
(use -source 7 or higher to enable try-with-resources)
[INFO] 2 errors 
[INFO] -------------------------------------------------------------
[INFO] ---------------------------------------------------------------------- 
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.451 s
[INFO] Finished at: 2018-06-14T14:26:40+05:30
[INFO] Final Memory: 7M/20M

错误指向时的代码。通常在 eclipse 中显示编译错误,并建议将项目编译更改为 JavaSE-1.7,我已更改。当 Maven 构建显示错误时,它在 Eclipse 中没有显示任何红线。

try (FileWriter fw = new FileWriter(filesPath + "DataMaskOutput.txt", true);
        BufferedWriter bw = new BufferedWriter(fw);
        PrintWriter out = new PrintWriter(bw)) {
    out.println(applId + "-->" + updateApplSeedNbr);
    out.close();
} catch (IOException e) {
    e.printStackTrace();
}

根据 maven-compiler-plugin docs,您可以在 pom.xml:

中使用 <properties>
<project>
  ...
  <properties>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
  </properties>
  ...
</project>