This is my simple code from a Maven project which has try-with-resources.I use eclipse as my IDE.
public class Hello {
public static void main(String[] args) {
try(FileInputStream fi = new FileInputStream("ANC")){
} catch (IOException e) {
e.printStackTrace();
}
}
}
When I build this using clean package -U
it gives me the following error.
Hello.java:[11,20] try-with-resources is not supported in -source 1.5
(use -source 7 or higher to enable try-with-resources).
However,I have my java compiler to be set at Java 1.8 and in Jave Build path JRE System Library is also JDK 1.8.Still this error persists.
This is my POM file ( minus the junit dependency )
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.commonutil</groupId>
<artifactId>PropertyFile</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>PropertyFile</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
Note : Setting the target and source in pom.xml did not help either. Any help regarding this is appreciated.Thank you.