13

I am trying to build an existing maven project on a fresh install of the latest netbeans but am getting the following error, any help is much appreciated:

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

I think it has something to do with paths but am not sure exactly. Here is the contents of my /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
Rory
  • 1,805
  • 7
  • 31
  • 45

3 Answers3

14

Thanks oers, you were right.

I needed to install JDK 1.7/Java 7, and then edit the netbeans config file in the netbeans install directory /etc/netbeans.conf to point to where I installed the new version of Java:

    # Default location of JDK, can be overridden by using --jdkhome <dir>:
    netbeans_jdkhome="/users/rory/Documents/jdk1.7.0_02"
Rory
  • 1,805
  • 7
  • 31
  • 45
  • 2
    Since I had the same problem with IntelliJ: The solution there is to set the JRE version in the Maven|Runner project settings. – sunside Mar 07 '12 at 21:47
  • It seems to be a strange fact that if you install a new jdk when Netbeans is already installed, you need to manipulate the netbeans_jdkhome as describe here. Netbeans should be able to detect which is the latest jdk and use that if what the netbeans_jdkhome points to is not found. This must be a bug in Netbeans from the days of old. – carl Sep 14 '15 at 10:17
9

Add the following to your pom under build and plugins it should target 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>
Paul Whelan
  • 16,574
  • 12
  • 50
  • 83
  • Thanks, but when I changed it I now get the error: diamond operator is not supported in -source 1.6 (use -source 7 or higher to enable diamond operator) ---- (Alt-Enter shows hints) – Rory Jan 25 '12 at 14:24
  • 3
    @Rory if you need java 1.7 language features then you have to install a java 1.7 jdk on your machine – oers Jan 25 '12 at 14:33
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>

If Platform or Source/Binary Format in project properties is not same with this configuration it gives error

Malcolmxappa
  • 103
  • 2
  • 12