I'm getting into Java7 development and I've added JDK7 into Java Platforms and have selected it in the project properties.
But when I'm compiling, I get messages like:
warning: java/lang/Boolean.class(java/lang:Boolean.class): major version 51 is newer than 50, the highest major version supported by this compiler. It is recommended that the compiler be upgraded.
and
javac: invalid target release: 1.7 /Applications/NetBeans/NetBeans 7.1.app/Contents/Resources/NetBeans/harness/suite.xml:184: The following error occurred while executing this line: /Applications/NetBeans/NetBeans 7.1.app/Contents/Resources/NetBeans/harness/common.xml:206: Compile failed; see the compiler error output for details.
So as far as I understand Netbeans is using javac 1.6. How can I change in to 1.7?
I'm writing a NetBeans Platform app and in main app Properties I've set: Java Platform = JDK 1.7. And in one of the module's Properties I've set Source level = 1.7.
suite.xml (184 is the second line here)
<target name="build" depends="-init,branding,release,-hide-excluded-modules" description="Build all modules in the suite."> <subant target="netbeans" buildpath="${modules.sorted}" inheritrefs="false" inheritall="false"> <property name="cluster.path.evaluated" value="${cluster.path.evaluated}"/> <!-- Just for speed of pre-7.0 projects --> </subant> </target>
common.xml (206 is the second line here)
<nb-javac srcdir="${src.dir}" destdir="${build.classes.dir}" debug="${build.compiler.debug}" debuglevel="${build.compiler.debuglevel}" encoding="UTF-8" deprecation="${build.compiler.deprecation}" optimize="${build.compiler.optimize}" source="${javac.source}" target="${javac.target}" includeantruntime="false"> <classpath refid="cp"/> <compilerarg line="${javac.compilerargs}"/> <processorpath refid="processor.cp"/> </nb-javac>
Unlike Eclipse (which uses its own Eclipse Java Compiler), Netbeans actually uses the internal API of javac for compiling, syntax highlighting, and error detection.
You can get your default JDK by: menu Tools → Java Platforms. There you can add all your JDKs and watch their bibs. If you want to change the default one, you need to go the path C:\Program Files\NetBeans 8.2\etc and you need to change the netbeans. conf file.
On the main NetBeans menu, choose Build → Build Main Project. The output window shows a successful compilation. If the compilation isn't successful, make changes to the code in the editor window, and try compiling again.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With