1

I have a Maven project in Eclipse. While building its showing error:

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

Code at when Error is pointing. Generally is shown compile error in eclipse and suggested to change project compile to JavaSE-1.7 and I have changed. It is not showing any red line in Eclipse while Maven build is showing error.

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();
}
Karol Dowbecki
  • 43,645
  • 9
  • 78
  • 111
paardhu
  • 101
  • 8

1 Answers1

3

As per maven-compiler-plugin docs you can use the <properties> in the pom.xml:

<project>
  ...
  <properties>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
  </properties>
  ...
</project>
Karol Dowbecki
  • 43,645
  • 9
  • 78
  • 111
  • It solved my problem. But why its taken 1.5 initially ,i have not set the properties in pom.xml – paardhu Jun 14 '18 at 10:01
  • 1
    As per [docs](https://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html) the `source` and `target` properties have default value of `1.5`. Historic compatibility reasons I assume. – Karol Dowbecki Jun 14 '18 at 10:04