Netbeans Maven错误:javac:无效的目标版本:1.7

时间:2012-01-25 12:00:02

标签: netbeans maven java

我正在尝试在最新netbeans的全新安装上构建现有的maven项目但是我收到以下错误,非常感谢任何帮助:

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project com.rory.ngp.test: Compilation failure
Failure executing javac, but could not parse the error:
javac: invalid target release: 1.7

我认为它与路径有关,但我不确定。以下是我/usr/lib/jvm directory;

的内容
bash-4.1$ pwd
/usr/lib/jvm
bash-4.1$ ls   
java                               java-openjdk   jre-1.6.0-openjdk.x86_64
java-1.5.0-gcj-1.5.0.0             jre            jre-gcj
java-1.6.0                         jre-1.5.0      jre-openjdk
java-1.6.0-openjdk-1.6.0.0.x86_64  jre-1.5.0-gcj
java-1.6.0-openjdk.x86_64          jre-1.6.0

3 个答案:

答案 0 :(得分:14)

谢谢你,你是对的。

我需要安装JDK 1.7 / Java 7,然后在netbeans安装目录/etc/netbeans.conf中编辑netbeans配置文件,指向我安装新版Java的位置:

    # Default location of JDK, can be overridden by using --jdkhome <dir>:
    netbeans_jdkhome="/users/rory/Documents/jdk1.7.0_02"

答案 1 :(得分:9)

在构建和插件下将以下内容添加到您的pom中,它应该以1.6

为目标
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>

答案 2 :(得分:0)

<plugin>
 <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
   <version>2.3.2</version>
    <configuration>
     <source>1.6</source>
      <target>1.6</target>
       <compilerArguments>
            <endorseddirs>${endorsed.dir}</endorseddirs>
       </compilerArguments>
   </configuration>
</plugin>

如果项目属性中的平台或源/二进制格式与此配置不同,则会出现错误