right click on ur project in eclipse and open "Run Configurations"..check the jre version there. some times this will not change by default in eclipse,after even changing the version in the buildpath.
try using a newer version of the maven compiler plugin:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
also, specifying source file encoding in maven is better done globally:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
EDIT: As this answer is still getting attention i'd just like to point out that the latest values (as of latest edit) are 3.2 for maven compiler plugin and 1.8 for java, as questions about compiling java 8 code via maven are bound to appear soon :-)
Try to change Java compiler settings in Properties in Eclipse-
Goto: Preferences->Java->Compiler->Compiler Compliance Level-> 1.7 Apply Ok
Restart IDE.
Confirm Compiler setting for project- Goto: Project Properties->Java Compiler-> Uncheck(Use Compliance from execution environment 'JavaSE-1.6' on the java Build path.) and select 1.7 from the dropdown. (Ignore if already 1.7)
Restart IDE.
If still the problem persist- Run individual test cases using command in terminal-
mvn -Dtest=<test class name> test
I had the same problem. I found that this is because the Maven script looks at the CurrentJDK link below and finds a 1.6 JDK. Even if you install the latest JDK this is not resolved. While you could just set JAVA_HOME in your $HOME/.bash_profile script I chose to fix the symbolic link instead as follows:
ls -l /System/Library/Frameworks/JavaVM.framework/Versions/
total 64
lrwxr-xr-x 1 root wheel 10 30 Oct 16:18 1.4 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 30 Oct 16:18 1.4.2 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 30 Oct 16:18 1.5 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 30 Oct 16:18 1.5.0 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 30 Oct 16:18 1.6 -> CurrentJDK
lrwxr-xr-x 1 root wheel 10 30 Oct 16:18 1.6.0 -> CurrentJDK
drwxr-xr-x 9 root wheel 306 11 Nov 21:20 A
lrwxr-xr-x 1 root wheel 1 30 Oct 16:18 Current -> A
lrwxr-xr-x 1 root wheel 59 30 Oct 16:18 CurrentJDK -> /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents
Notice that CurrentJDK points at 1.6.0.jdk
To fix it I ran the following commands (you should check your installed version and adapt accordingly).
sudo rm /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK
sudo ln -s /Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/ /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK
Check the mvn
script in your maven installation to see how it's building the command. Perhaps you or someone else has hard-coded a JAVA_HOME
in there and forgotten about it.
I had this problem in IntelliJ IDEA 14 until I went into File menu --> Project Structure, changing project SDK to 1.7 and project language level to 7.