• Maven 【ERROR】 不再支持源选项 5。请使用 7或更高版本解决方案:修改Maven默认JDK(含完整代码及详细教程)



    一、前言

    博主在遇到这个问题时,找遍了百度的方法也没办法解决(浪费了一天时间。。。)但是通过搜索“如何修改Maven默认jdk”后,找到了解决方法并成功运行,为了便于大家找到本文,所以标题以报错命名,也给受到同样困惑的小伙伴带来便利

    二、项目场景

    在初学Maven时,观看网课的小伙伴都会跟着老师一步步构建一个Maven项目(不使用任何程序),其中有一个步骤就是要在在Dos窗口输入命令并构建项目,此次问题也就是出在运行命令的时候


    三、问题描述

    Maven 【ERROR】 不再支持源选项 5。请使用 6 或更高版本
    在这里插入图片描述

    四、原因分析

    没有修改Maven默认的JDK版本

    五、解决方案

    1. 查看本机安装的jdk版本

    首先打开控制面板,打开Java
    在这里插入图片描述
    然后选择Java,点击查看

    在这里插入图片描述

    2. 找到settings.xml文件

    这个文件一般是放在apache-maven-3.6.3\conf下的
    在这里插入图片描述

    3. 编辑settings.xml文件

    注意:不用修改原来的代码,而是增加如下代码即可(jdk版本以自己安装的为准)

    <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>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

    完整代码如下:

    <profile>
    
    <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>
    
          <id>jdk-1.4</id>
    
          <activation>
            <jdk>1.4</jdk>
          </activation>
    
          <repositories>
            <repository>
              <id>jdk1.4</id>
              <name>Repository for JDK 1.4 builds</name>
              <url>http://www.myhost.com/maven/jdk8</url>
              <layout>default</layout>
              <snapshotPolicy>always</snapshotPolicy>
            </repository>
          </repositories>
        </profile>
    
        -->
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33

    4.找到pom.xml文件

    这个文件一般是在自己创建的文件夹下的E:\project\project-java(如果是跟着黑马程序员的网课看的话,路径应该是与我的一致,除了盘不一致)

    在这里插入图片描述

    5.修改pom.xml文件

    注意:不用修改原来的代码,而是增加如下代码即可(jdk版本以自己的为准)

    <build> 
    <plugins> 
    <plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
    <source>1.8</source>
    <target>1.8</target>
    <encoding>${file_encoding}</encoding>
    </configuration>
    </plugin>
    </plugins>
    </build>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    完整代码如下

    <?xml version="1.0" encoding="UTF-8" ?>
     
    <project 
            xmlns="http://maven.apache.org/POM/4.0.0" 
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
            xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    
    <modelVersion>4.0.0</modelVersion>
    
    
        <groupId>com.itheima</groupId>
        <artifactId>project-java</artifactId>
        <version>1.0</version>
        <packaging>jar</packaging>
    
    <build> 
    <plugins> 
    <plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
    <source>1.8</source>
    <target>1.8</target>
    <encoding>${file_encoding}</encoding>
    </configuration>
    </plugin>
    </plugins>
    </build>
    
        <dependencies>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.12</version>
            </dependency>
        </dependencies>
     
    </project>
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39

    六、验证

    在这里插入图片描述

    七、结语

    如果还有任何问题欢迎留言评论

  • 相关阅读:
    golang的超时处理使用技巧
    设计模式-命令模式
    Spring更简单的使用方法
    165-手表品牌浅看一下
    双向链表的基本操作怎么编译
    【C++&Python&Java】字符处理详细解读_字符_ASCLL码_字母数字转换_算法竞赛_开发语言
    Worthington丨Worthington胶原酶原材料认证
    数据处理任务——知识点总结
    08——驾校科目一考试——布局按钮
    服务器机器学习环境搭建(包括AanConda的安装和Pytorch的安装)
  • 原文地址:https://blog.csdn.net/Alita233_/article/details/127911110