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:\users\Hxinguan.m2\settings.xml,如下图。只要把设置好的settings.xml文件复制到该目录下,然后update project就好了。
在这里插入图片描述

posted @ 2020-03-26 21:53  超级小白龙  阅读(1725)  评论(0编辑  收藏  举报