-1

After doing maven clean install then running mvn install in eclipse getting this error, not sure what it is referring:

[ERROR] /Users/user1/Desktop/proj1/src/main/java/com/proj/proj1/dao/testDAO.java:[18,21] try-with-resources is not supported in -source 1.5
[ERROR] (use -source 7 or higher to enable try-with-resources)
raptor496
  • 237
  • 1
  • 3
  • 12
  • It says your code is using Java 7 features but your compiler is trying to use Java 5 for compilation. Since Java 5 does not know anything about Java 7 features, you get an error. – takendarkk May 30 '17 at 15:08
  • wrong java versions –  May 30 '17 at 15:09

2 Answers2

0

try-with-resources is a Java 7 specificity.

So, as you are using Maven, you have to configure the Maven compiler plugin in your pom.xml to use at least Java 7.

If you use for example JDK 8, you could add this properties in the build element of the pom.xml :

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

source and target must not necessarily have the same value but in the very most of cases, it is better.

davidxxx
  • 125,838
  • 23
  • 214
  • 215
0

Add a properties tag in your POM.xml to ensure that you will be working using Java 8 (try-with-resources requirement). Check if you have the Java 1.8 sdk installed, and your IDE is properly configured.

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
</properties>
Anderson Marques
  • 808
  • 8
  • 13