zoukankan      html  css  js  c++  java
  • Maven 项目报出警告:Warning:java: source value 1.5 is obsolete and will be removed in a future release

    感谢原文作者:Hxinguan
    原文链接:https://www.cnblogs.com/Hxinguan/p/6132446.html

    问题:

    1、创建maven项目的时候,jdk版本是1.5版本,而自己安装的是1.7或者1.8版本。

    2、每次右键项目名-maven->update project 时候,项目jdk版本变了,变回1.5版本或者其他版本

    3、使用 Maven 项目运行程序时,报出警告

    Warning:java: source value 1.5 is obsolete and will be removed in a future release
    Warning:java: target value 1.5 is obsolete and will be removed in a future release
    Warning:java: To suppress warnings about obsolete options, use -Xlint:-options.

    原因:

    这是因为 Maven 内置 jdk 编译环境是 1.5 版本,Maven 3.0版本后为1.6版本。
    使用 maven 开发项目时,不会使用 IDEA 设置的 jdk,而是使用 Maven 内置的 jdk 编译器。
    如需使用较新的版本,需要我们自己指定版本号。

    解决办法:

    解决办法一:在项目中的pom.xml指定jdk版本,如下:

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

    这个方法只能保证该项目是jdk1.8版本,每次新建项目都得加上面代码,不推荐使用,推荐第二种方法。

    解决方法二:在maven的安装目录找到settings.xml文件,在里面添加如下代码

    <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>
    

    添加完后,在对eclipse进行设置。window->preferences->maven->user settings,user settings那里选择maven安装目录下的settings.xml文件。如下图
    在这里插入图片描述
    设置完成后,右键项目->maven->update project,这样每次新建maven项目都默认为jdk1.8版本了

    解决方法三:

    在解决方法二中,user settings的默认settigs.xml文件路径为:c:usersHxinguan.m2settings.xml,如下图。只要把设置好的settings.xml文件复制到该目录下,然后update project就好了。
    在这里插入图片描述

  • 相关阅读:
    奶萨的团队框架(Grid)个人设置技巧以及使用方法
    巫妖王之怒:3.35暗牧输出手法入门指引
    WLK3.3.5治疗怎么玩:治疗职业心得汇总
    WLK奥术fs怎么打高DPS
    战斗贼入门级输出循环
    3.35国服法师DPS提升指引 奥与火的双重奏
    3.35奶萨新手无聊看看帖
    邪冰双手(鲜血领域)——新手推荐,AOE和移动战都不错
    WLK 防骑T
    WLK防骑拉怪手法(要有序排列再给我答案)
  • 原文地址:https://www.cnblogs.com/tfxz/p/12621485.html
Copyright © 2011-2022 走看看