开发者

Maven : error: generics are not supported in -source 1.3 , I am using 1.6

开发者 https://www.devze.com 2023-04-09 23:54 出处:网络
I have imported an existing Maven project into Eclipse ID开发者_如何学编程E . I have modified somecode in it , it compiled successfully ,

I have imported an existing Maven project into Eclipse ID开发者_如何学编程E . I have modified some code in it , it compiled successfully , I am using Java 1.6 as compiler and when i am trying to run maven clean install -X

Its giving the following error

could not parse error message: (use -source 5 or higher to enable generics) D:\bayer\util\src\main\java\com\tata\bayer\util\BrokerageCalendar.java:179: error: generics are not supported in -source 1.3

   private static Hashtable<String, Boolean> nyseHolidays = new Hashtable<String, Boolean>();
                           ^

could not parse error message:   (use -source 5 or higher to enable generics)
D:\bayer\util\src\main\java\com\tata\bayer\util\APIHttpXmlClient.java:27: error: generics are not supported in -source 1.3
                        Class<? extends APIResponse> responseClass) {
                         ^

Please suggest any ideas as how to resolve this ??


Did you declare that you want to use java 1.6 in your project pom.xml?:

<build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>2.3.2</version>
                    <configuration>
                        <source>1.6</source>
                        <target>1.6</target>
                        <compilerArgument></compilerArgument>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>


Configuring the Maven Compiler Plugin will fix the problem. It turns out the problem was caused by the Maven3 package in the Ubuntu repository. An alternate fix is to download Maven 3 from the Apache website which uses a more up to date Compiler plugin.

I wanted to know why this was happening when the documentation states the default Java source is 1.5. To see what mvn is using for your compiler plugin use:

mvn help:effective-pom

My Maven Compiler Plugin was 2.0.2 even though I was using Maven 3.0.4 from the Ubuntu packages. When I run the same command using Maven 3.0.4 from Apache I have a plugin version 2.3.2, which defaults to Java 1.5 as expected.


You have to configure the Maven Compiler Plugin.

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-compiler-plugin</artifactId>
  <version>2.3</version>
  <configuration>
    <source>1.6</source>
    <target>1.6</target>
  </configuration>
</plugin>


Another way that doesn't involve modifying the pom is to specify the source and target in the command line:

mvn clean install -Dmaven.compiler.source=1.6 -Dmaven.compiler.target=1.6

Note that this should be avoided generally as the build cannot be guaranteed to be repeatable this way.


I'd prefer this:

<properties>
    <maven.compiler.source>1.5</maven.compiler.source>
    <maven.compiler.target>1.5</maven.compiler.target>
    ...
0

精彩评论

暂无评论...
验证码 换一张
取 消