23

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?

EDIT:

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.

EDIT2

  • Mac OS 10.7.3
  • NetBeans IDE 7.1 (Build 201112071828)
  • openjdk version "1.7.0-internal"
  • OpenJDK Runtime Environment (build 1.7.0-internal-uko_2012_02_15_11_51-b00)
  • OpenJDK 64-Bit Server VM (build 23.0-b15, mixed mode)

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>
Uko
  • 13,134
  • 6
  • 58
  • 106

3 Answers3

31

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"                          ;as opposed to ${javac.fork}
      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

Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
alain.janinm
  • 19,951
  • 10
  • 65
  • 112
  • 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**. So the problem is not in project setup – Uko Feb 15 '12 at 17:06
  • 1
    Check this link maybe the solution is there for you too http://netbeans.org/bugzilla/show_bug.cgi?id=203088 – alain.janinm Feb 15 '12 at 17:10
  • Yes, but the problem is in Web apps, and I'm using Java SE. In my app, I don't have a _javac_ task in my `build.xml`. And the error points not to my ant build scripts, but to some _harness_ xmls – Uko Feb 15 '12 at 17:31
  • Ok, can you share in the question the XML lines `suite.xml:184` and `common.xml:206`? The compiler said the errors are here. And can you give your netbeans version and your os? – alain.janinm Feb 15 '12 at 18:51
  • Have you tried to add `fork="yes"` in the `` tag in common.xml? The other pb is that jdk 1.7 is still a preview for Mac Os X so you might have bugs... – alain.janinm Feb 15 '12 at 19:36
  • A guy form Netbeans suggested running IDE in JDK7. Do you know how this can be done? – Uko Feb 17 '12 at 06:58
  • 1
    Edit the netbeans conf file, mine is at : `~/.netbeans/7.0/etc/app.conf`. Uncomment the `jdkhome=` line and set jdk7. – alain.janinm Feb 17 '12 at 08:51
  • On mac it's in `/Applications/NetBeans/NetBeans\ 7.1.app/Contents/Resources/NetBeans/harness/etc/app.conf` but it's not working no idea why. But `netbeans --jdkhome /Java7/Home/dir` works fine and fixes the problem in some way. @alain.janinm, thank you very much for help. Can you add a solution steps from comments to your answer, so I can mark it as a solution. – Uko Feb 17 '12 at 09:58
  • Ok good! I've add in my answer what you tried. If you think of some other precisions you can also edit my post! – alain.janinm Feb 17 '12 at 10:07
  • Thank you, thank you. An alternative work-around that won't break when build-impl.xml gets regenerated is to put the following at the top of your build.xml before it includes build-impl.xml: `` – Sarel Botha Jun 21 '13 at 15:19
1

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.

Mariano D'Ascanio
  • 1,202
  • 2
  • 16
  • 17
0

I was using Netbeans 8.2 and the jdk was 1.8 and I wanted to compile the project in lower version 1.7 of Java.

  • Right click on your project and go to the properties tab
  • Click on libraries
  • Then click on manage libraries
  • After that Add platform and add your javapath and close

Then you can build your project.

alain.janinm
  • 19,951
  • 10
  • 65
  • 112
mahesh
  • 1