如何在 Netbeans 中设置 Java 编译器 [英] How to set a java compiler in Netbeans

查看:35
本文介绍了如何在 Netbeans 中设置 Java 编译器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从事 Java7 开发,我已将 JDK7 添加到 Java 平台,并在项目属性中选择了它.

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.

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.

据我所知,Netbeans 使用的是 javac 1.6.我怎样才能改成 1.7?

So as far as I understand Netbeans is using javac 1.6. How can I change in to 1.7?

我正在编写一个 NetBeans 平台应用程序,并且在我设置的主应用程序属性中:Java 平台 = JDK 1.7.在模块的其中一个属性中,我设置了 Source level = 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.

  • Mac 操作系统 10.7.3
  • NetBeans IDE 7.1(内部版本 201112071828)
  • openjdk 版本1.7.0-内部"
  • OpenJDK 运行时环境(构建 1.7.0-internal-uko_2012_02_15_11_51-b00)
  • OpenJDK 64 位服务器 VM(构建 23.0-b15,混合模式)
  • 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 是这里的第二行)

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 是这里的第二行)

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>

推荐答案

右键单击您的项目 --> 项目属性

Right click on your project --> Project Properties

然后在 Sources 中将 Source/Binary Format 设置为 JDK 7.

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

编辑 1:

存在 NetBeans 问题:

在 J2SE 项目中工作正常,Web 项目特定问题.问题是 fork="false" JDK 7.0 参数传递给 JDK 6.0编译器.可执行文件需要 fork="true".

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".

在build-iml.xml的第293行

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}">

应该变成:

<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}">

编辑 2(如果第一个提示不起作用):

尝试在 JDK7 中运行 Netbeans IDE.

Try to run Netbeans IDE in JDK7.

编辑 Netbeans 配置文件:

Edit Netbeans conf file :

Linux

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

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

Mac Os X

/Applications/NetBeans/NetBeans7.1.app/Contents/Resources/NetBeans/harness/etc/app.conf

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

jdkhome= 行中添加 jdk7 路径.

Add the jdk7 path in the line jdkhome=.

使用 :

netbeans --jdkhome/Java7/Home/dir

netbeans --jdkhome /Java7/Home/dir

这篇关于如何在 Netbeans 中设置 Java 编译器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆