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

Ror*_*ory 13 java netbeans maven

我正在尝试在最新的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
Run Code Online (Sandbox Code Playgroud)

我认为它与路径有关,但我不确定.这是我的内容/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
Run Code Online (Sandbox Code Playgroud)

Ror*_*ory 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"
Run Code Online (Sandbox Code Playgroud)

  • 由于我在IntelliJ中遇到了同样的问题:解决方案是在Maven | Runner项目设置中设置JRE版本. (2认同)

Pau*_*lan 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>
Run Code Online (Sandbox Code Playgroud)

  • @Rory如果你需要java 1.7语言功能,那么你必须在你的机器上安装java 1.7 jdk (3认同)