How to set a java compiler in Netbeans

Right click on your project --> Project Properties

Then in Sources set Source/Binary Format to JDK 7.

EDIT 1 :

There is a NetBeans issue:

Works fine in J2SE project, Web project specific problem. The problem is that fork="false" the JDK 7.0 params are passed to JDK 6.0 compiler. The executable requires fork="true".

On the line 293 of build-iml.xml the

<javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}"
encoding="${source.encoding}" excludes="@{excludes}"
executable="${platform.javac}" fork="${javac.fork}" includeantruntime="false"
includes="@{includes}" source="${javac.source}" srcdir="@{srcdir}"
target="${javac.target}" tempdir="${java.io.tmpdir}">

should become:

<javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}"
encoding="${source.encoding}" excludes="@{excludes}"
executable="${platform.javac}" fork="yes" includeantruntime="false"
includes="@{includes}" source="${javac.source}" srcdir="@{srcdir}"
target="${javac.target}" tempdir="${java.io.tmpdir}">

EDIT 2 (if first tips don't work):

Try to run Netbeans IDE in JDK7.

Edit Netbeans conf file :

Linux

~/.netbeans/7.0/etc/app.conf

Mac Os X

/Applications/NetBeans/NetBeans\ 7.1.app/Contents/Resources/NetBeans/harness/etc/app.conf

Add the jdk7 path in the line jdkhome=.

Or

Launch netbeans using :

netbeans --jdkhome /Java7/Home/dir


Update for NetBeans 8:

The file to edit is

/Applications/NetBeans/NetBeans\ 8.0.app/Contents/Resources/NetBeans/harness/etc/app.conf

I added the line

jdkhome="/Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk"

and restarted NetBeans, it accepted JDK 1.7 U67 as its compilation platform.