zoukankan      html  css  js  c++  java
  • 解决:Java source1.5不支持diamond运算符,请使用source 7或更高版本以启用diamond运算符

    Maven默认用的是JDK1.5去编译

    diamond运算符,指的是JDK1.7的一个新特性

    List<String> list = new ArrayList<String>(); // 老版本写法List<String> list = new ArrayList<>(); // JDK1.7及以后的写法

    所以Maven默认使用JDK1.5去编译是不认识这个东西的,针对这种问题,在网上找了三种解决方案:

    Ⅰ :在项目pom.xml中加入下面的配置即可

    <properties> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target></properties>

    Ⅱ:直接在模块pom.xml中配置Maven的编译插件也是可以的,像下面这样:

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

      

    Ⅲ:另外还有一种最终的解决方案,适用于idea下配置Maven的所有项目:

    在配置的maven安装包的setting.xml中的profiles标签中加入以下标签

    <profile> <id>jdk-1.8</id> <activation> <activeByDefault>true</activeByDefault> <jdk>1.8</jdk> </activation> <properties> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion> </properties> </profile>

    这样之后就不会出现每次新创建的maven项目默认JDK版本都是1.5版本的了。

    备注:

    第二种解决方案亲测有效。有的人电脑没有这段代码后会打包失败,有的电脑却不会,暂时不知什么原因。

  • 相关阅读:
    Axure流程图
    Axure工作区间
    Axure简介
    Java知识导航总图
    SQL筛选出同一学科的时间最新的记录
    从高版本JDK换成低版本JDK报错Unsupported major.minor version 52.0
    java.lang.IllegalArgumentException: No converter found for return value of type
    httpClient创建对象、设置超时
    sql 查出一张表中重复的所有记录数据
    java List分批处理
  • 原文地址:https://www.cnblogs.com/059212315/p/12122820.html
Copyright © 2011-2022 走看看