Maven Compile Error
Asked Answered
M

9

12

When I build and run my program in Netbeans, it works without a problem. But with same pom.xml file when I try "mvn compile" I get this error:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile (default-compile) on project hadoop-test: Compilation failure
[ERROR] /home/metin/NetBeansProjects/hadoop-test/src/main/java/com/citusdata/hadoop/HadoopTest.java:[53,8] error: generics are not supported in -source 1.3

My java version is not 1.3, here the result of "mvn -version"

Apache Maven 3.0.4
Maven home: /usr/share/maven
Java version: 1.7.0_03, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-7-openjdk-amd64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.2.0-27-generic", arch: "amd64", family: "unix"

and this is the line 53:

Token<BlockTokenIdentifier> token = locatedBlock.getBlockToken();
Maureenmaureene answered 8/11, 2012 at 16:18 Comment(1)
Are you specifying a particular compiler plugin? Is there anything else in your pom?Lawley
P
22

The problem is that maven-compiler-plugin in Maven2 by default uses -source 1.3 and target 1.3

You can fix it by adding this to your pom:

    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-compiler-plugin</artifactId>
      <configuration>
        <compilerVersion>1.5</compilerVersion>
        <source>1.5</source>
        <target>1.5</target>
      </configuration>
    </plugin>

It's practical to put this into pluginManagement section in your topmost parent pom so that your derived poms do not need to care about this.

Preuss answered 8/11, 2012 at 16:22 Comment(3)
Not sure, I am not a NetBeans user, but perhaps NB adds some properties (like maven.compiler.source, maven.compiler.target) or enforces a newer version of maven-compiler-plugin which already has the value of 1.5 as the default - maven.apache.org/plugins/maven-compiler-plugin/…Preuss
My maven version is 3.0.4. How will end up using an old maven-compiler-plugin ?Maureenmaureene
this is surely possible, for instance if it 'hides' in a parent pom's pluginManagement... just a guessPreuss
H
5

You have to add some informations in your pom.xml. Something like that:

   <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>
        </configuration>
  </plugin>
Huddersfield answered 8/11, 2012 at 16:21 Comment(0)
S
1

In your log, I see this line:

generics are not supported in -source 1.3

Check the source and target configuration of maven-compiler plug-in, and update it to 1.5.

Smedley answered 8/11, 2012 at 16:23 Comment(0)
C
0

It seems your maven compiler plugin version is 1.3.

Have a look at this link to force the compiler to run with JDK 1.7, http://maven.apache.org/plugins/maven-compiler-plugin/examples/compile-using-different-jdk.html

Carboxylate answered 8/11, 2012 at 16:22 Comment(0)
R
0

It seems your maven java home point to a jre not jdk

Java home: /usr/lib/jvm/java-7-openjdk-amd64/jre

You have to change it to a jdk.

Try java -version and see what is there

use /usr/sbin/alternatives --config java to change your java version.

Rabblerousing answered 8/11, 2012 at 16:24 Comment(0)
C
0

Here is a slightly different way to fix the same error in Eclipse Indigo.

  • Open your (maven) project in Eclipse.
  • right click on pom.xml
  • select ...Maven...Add Plugin
  • Enter:

      - groupId: org.apache.maven.plugins
      - artifactId: maven-compiler-plugin
      - version: 2.3.2
    

This will insert a new section in your pom.xml and open a window for editing.

Then you can add the source and target xml elements as described above to select the correct JRE.

The section looks like this in my project:

<build>
  <plugins>
     <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>
        </configuration>
     </plugin>
  </plugins>
</build>

Note the extra tags for "build" and "plugins" absent in some of the other posts.

Once you save the file, Eclipse will notify you that your pom is out of synch with your project.

You can then right click the project ...choose Maven..update project

A key insight for me was that Maven will automatically re-set the build path in Eclipse. Which you can verify by Project...build path..configure build path...Libraries.

So in essence this means you should not have to mess with directly configuring the build path in Eclipse if you are using a Maven project.

HTH

Creation answered 17/5, 2013 at 20:12 Comment(0)
B
0

Please Execute Maven Run from eclipse and then run mvn test from command prompt. In my case all issues resolved with this step.

Behaviorism answered 5/1, 2019 at 10:5 Comment(0)
S
0

Add this to Pom.xml

<properties>
    <maven.compiler.target>1.8</maven.compiler.target>
    <maven.compiler.source>1.8</maven.compiler.source>
</properties>
Salangi answered 11/6, 2020 at 17:10 Comment(0)
R
-1

If you are running your application with Java 8 and Spring Boot then you can fix this issue by adding the below lines to your pom.xml file

    <build>
            <plugins>
                    <plugin>
                            <groupId>org.springframework.boot</groupId>
                            <artifactId>spring-boot-maven-plugin</artifactId>
                    </plugin>
                    <plugin>
                            <groupId>org.apache.maven.plugins</groupId>
                            <artifactId>maven-compiler-plugin</artifactId>
                            <version>2.3.2</version>
                            <configuration>
                                 <source>1.8</source>
                                 <target>1.8</target>
                            </configuration>
                    </plugin>
            </plugins>
    </build>
Reneta answered 20/9, 2021 at 4:19 Comment(1)
This doesn't add anything to the accepted answer.Alkalimeter

© 2022 - 2024 — McMap. All rights reserved.