当前位置: 首页 > news >正文

IDEA Maven构建时报错:无效的目标发行版17

报错分析

报错原因:Maven 构建时,Java 版本配置不匹配

我安装的JDK版本是1.8,但由于种种原因,Maven构建时指定了 Java 17 作为目标发行版,从而导致错误

解决方案

首先,java -version,查看环境变量是否设置为了想要的JDK版本

1.检查pom文件

由于是在Maven构建时报错,所以优先检查pom文件,查看是否在properties中设置了错误的compiler.sourcecompiler.target

如上所示则是正确的(因为使用的JDK版本是1.8)

两个参数的含义分别是:

maven.compiler.source设置为 1.8,表示使用 Java 8 的语法规则来编译源代码

maven.compiler.target设置为 1.8,表示生成的字节码版本为 Java 8

2.查看Maven的有效配置

在编译时,可以使用 maven-compiler-plugin 插件指定所使用的JDK的版本,如果没有指定的话,将会使用默认配置,可以通过mvn help:effective-pom指令来查看默认配置,打印输出的内容结构如下:

  <modelVersion>4.0.0</modelVersion><groupId>com.why</groupId><artifactId>Sort-Array-Desc</artifactId><version>1.0-SNAPSHOT</version><properties><maven.compiler.compilerVersion>17</maven.compiler.compilerVersion><maven.compiler.source>17</maven.compiler.source><maven.compiler.target>17</maven.compiler.target><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties><dependencies><dependency><groupId>org.apache.hive</groupId><artifactId>hive-exec</artifactId><version>3.1.3</version><scope>compile</scope></dependency></dependencies><repositories><repository><snapshots><enabled>false</enabled></snapshots><id>central</id><name>Central Repository</name><url>https://repo.maven.apache.org/maven2</url></repository></repositories><pluginRepositories><pluginRepository><releases><updatePolicy>never</updatePolicy></releases><snapshots><enabled>false</enabled></snapshots><id>central</id><name>Central Repository</name><url>https://repo.maven.apache.org/maven2</url></pluginRepository></pluginRepositories><build><sourceDirectory>D:\codes\java\hive\Sort-Array-Desc\src\main\java</sourceDirectory><scriptSourceDirectory>D:\codes\java\hive\Sort-Array-Desc\src\main\scripts</scriptSourceDirectory><testSourceDirectory>D:\codes\java\hive\Sort-Array-Desc\src\test\java</testSourceDirectory><outputDirectory>D:\codes\java\hive\Sort-Array-Desc\target\classes</outputDirectory><testOutputDirectory>D:\codes\java\hive\Sort-Array-Desc\target\test-classes</testOutputDirectory><resources><resource><directory>D:\codes\java\hive\Sort-Array-Desc\src\main\resources</directory></resource></resources><testResources><testResource><directory>D:\codes\java\hive\Sort-Array-Desc\src\test\resources</directory></testResource></testResources><directory>D:\codes\java\hive\Sort-Array-Desc\target</directory><finalName>Sort-Array-Desc</finalName><pluginManagement><plugins><plugin><artifactId>maven-antrun-plugin</artifactId><version>1.3</version></plugin><plugin><artifactId>maven-assembly-plugin</artifactId><version>2.2-beta-5</version></plugin><plugin><artifactId>maven-dependency-plugin</artifactId><version>2.8</version></plugin><plugin><artifactId>maven-release-plugin</artifactId><version>2.5.3</version></plugin></plugins></pluginManagement><plugins><plugin><artifactId>maven-compiler-plugin</artifactId><version>3.8.1</version><executions><execution><id>default-compile</id><phase>compile</phase><goals><goal>compile</goal></goals><configuration><source>1.8</source><target>1.8</target></configuration></execution><execution><id>default-testCompile</id><phase>test-compile</phase><goals><goal>testCompile</goal></goals><configuration><source>1.8</source><target>1.8</target></configuration></execution></executions><configuration><source>1.8</source><target>1.8</target></configuration></plugin><plugin><artifactId>maven-clean-plugin</artifactId><version>2.5</version><executions><execution><id>default-clean</id><phase>clean</phase><goals><goal>clean</goal></goals></execution></executions></plugin><plugin><artifactId>maven-resources-plugin</artifactId><version>2.6</version><executions><execution><id>default-testResources</id><phase>process-test-resources</phase><goals><goal>testResources</goal></goals></execution><execution><id>default-resources</id><phase>process-resources</phase><goals><goal>resources</goal></goals></execution></executions></plugin><plugin><artifactId>maven-jar-plugin</artifactId><version>2.4</version><executions><execution><id>default-jar</id><phase>package</phase><goals><goal>jar</goal></goals></execution></executions></plugin><plugin><artifactId>maven-surefire-plugin</artifactId><version>2.12.4</version><executions><execution><id>default-test</id><phase>test</phase><goals><goal>test</goal></goals></execution></executions></plugin><plugin><artifactId>maven-install-plugin</artifactId><version>2.4</version><executions><execution><id>default-install</id><phase>install</phase><goals><goal>install</goal></goals></execution></executions></plugin><plugin><artifactId>maven-deploy-plugin</artifactId><version>2.7</version><executions><execution><id>default-deploy</id><phase>deploy</phase><goals><goal>deploy</goal></goals></execution></executions></plugin><plugin><artifactId>maven-site-plugin</artifactId><version>3.3</version><executions><execution><id>default-site</id><phase>site</phase><goals><goal>site</goal></goals><configuration><outputDirectory>D:\codes\java\hive\Sort-Array-Desc\target\site</outputDirectory><reportPlugins><reportPlugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-project-info-reports-plugin</artifactId></reportPlugin></reportPlugins></configuration></execution><execution><id>default-deploy</id><phase>site-deploy</phase><goals><goal>deploy</goal></goals><configuration><outputDirectory>D:\codes\java\hive\Sort-Array-Desc\target\site</outputDirectory><reportPlugins><reportPlugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-project-info-reports-plugin</artifactId></reportPlugin></reportPlugins></configuration></execution></executions><configuration><outputDirectory>D:\codes\java\hive\Sort-Array-Desc\target\site</outputDirectory><reportPlugins><reportPlugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-project-info-reports-plugin</artifactId></reportPlugin></reportPlugins></configuration></plugin></plugins></build><reporting><outputDirectory>D:\codes\java\hive\Sort-Array-Desc\target\site</outputDirectory></reporting>
</project>

可以看到,默认配置中,指定了源代码编译的语法规则以及生成的字节码文件版本都是Java 17,与我们本地的环境不符,因此·会报错:无效的目标发行版17

此时我很奇怪为什么默认会用Java 17的语法去进行编译,于是去查看maven的配置文件settings.xml,结果发现在<profiles></profiles>中添加了一个profile

可能是之前想要控制maven的默认编译行为,结果忘记了😂

所以解决方案有两种,第一种就是删除这里的配置,由于我所使用的maven版本是3.6.3,默认就是用Java 8 进行编译了:

第二种方法就是使用maven-compiler-plugin插件配置:

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

从而覆盖默认的配置

3.检查IDE中的JDK 配置

除了以上Maven配置的问题,我们也需要检查IDE中的配置,下述的方法在运行代码报错时同样可用

3.1 Project Structure

进入File -> Project Structure

Project标签页中,检查 Project SDK 是否设置为 1.8:

Modules 标签页中,检查 Module SDK以及language level是否设置为 1.8:

3.2 Java Compiler

进入File -> Settings -> Java Compiler,检查Target bytecode version是否设置为1…8:

相关文章:

IDEA Maven构建时报错:无效的目标发行版17

报错分析 报错原因&#xff1a;Maven 构建时&#xff0c;Java 版本配置不匹配 我安装的JDK版本是1.8&#xff0c;但由于种种原因&#xff0c;Maven构建时指定了 Java 17 作为目标发行版&#xff0c;从而导致错误 解决方案 首先&#xff0c;java -version&#xff0c;查看环…...

javafx 将项目打包为 Windows 的可执行文件exe

要将 JavaFX 项目打包为 .exe 文件&#xff0c;你可以使用一些工具将你的应用程序封装为 Windows 可执行文件。以下是两种常用的方法&#xff1a; 方法 1&#xff1a;使用 jpackage&#xff08;适用于 JDK 14 及更高版本&#xff09; jpackage 是 JDK 内置的工具&#xff0c;…...

Python操作Excel的库openpyxl使用入门

openpyxl 是一个用于读写 Excel 2010 xlsx/xlsm/xltx/xltm 文件的 Python 库。以下是一些 openpyxl 的基本使用方法&#xff1a; 安装 openpyxl 首先&#xff0c;确保已经安装了 openpyxl。如果没有安装&#xff0c;可以使用以下命令进行安装&#xff1a; pip install openp…...

数据通过canal 同步es,存在延迟问题,解决方案

当使用 Canal 同步数据到 Elasticsearch&#xff08;ES&#xff09;时&#xff0c;出现延迟问题通常源于多个因素&#xff0c;如 Canal 配置、网络延迟、ES 的负载和性能瓶颈等。以下是一些解决方案&#xff0c;帮助减少和解决延迟问题&#xff1a; 1. 优化 Canal 配置 Canal…...

了解Node.js

Node.js是一个基于V8引擎的JavaScript运行时环境&#xff0c;它允许JavaScript代码在服务器端运行&#xff0c;从而实现后端开发。Node.js的出现&#xff0c;使得前端开发人员可以利用他们已经掌握的JavaScript技能&#xff0c;扩展技能树并成为全栈开发人员。本文将深入浅出地…...

Android Studio创建新项目并引入第三方jar、aar库驱动NFC读写器读写IC卡

本示例使用设备&#xff1a;https://item.taobao.com/item.htm?spma21dvs.23580594.0.0.52de2c1bbW3AUC&ftt&id615391857885 一、打开Android Studio,点击 File> New>New project 菜单&#xff0c;选择 要创建的项目模版&#xff0c;点击 Next 二、输入项目名称…...

Oracle Dataguard(主库为双节点集群)配置详解(4):配置备库

Oracle Dataguard&#xff08;主库为双节点集群&#xff09;配置详解&#xff08;4&#xff09;&#xff1a;配置备库 目录 Oracle Dataguard&#xff08;主库为双节点集群&#xff09;配置详解&#xff08;4&#xff09;&#xff1a;配置备库一、为备库配置静态监听1、配置 li…...

前端炫酷动画--文字(二)

目录 一、弧形边框选项卡 二、零宽字符 三、目录滚动时自动高亮 四、高亮关键字 五、文字描边 六、按钮边框的旋转动画 七、视频文字特效 八、立体文字特效让文字立起来 九、文字连续光影特效 十、重复渐变的边框 十一、磨砂玻璃效果 十二、FLIP动画 一、弧形边框…...

ceph 数据均衡

实现数据均衡的主要方法 在 Ceph 集群中,实现 OSD(对象存储守护进程)之间的数据均衡对于提升性能和资源利用率至关重要。以下是实现数据均衡的主要方法: 1. 调整 OSD 权重(Reweight) 通过调整 OSD 的权重,可以控制数据在各个 OSD 之间的分布。Ceph 提供了根据利用率或…...

代码随想录算法训练营day29

代码随想录算法训练营 —day29 文章目录 代码随想录算法训练营前言一、134. 加油站暴力解法贪心算法 二、135. 分发糖果三、860. 柠檬水找零四、406.根据身高重建队列vector版list版 总结 前言 今天是算法营的第29天&#xff0c;希望自己能够坚持下来&#xff01; 今日任务&a…...

android studio根据包名获取当前安装包信息

package com.example.myapplication2;import android.content.Context; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.util.Log;/**** 获取版本信息*/ public class SystemHelper {/*** 获取本地软件版本号*/public stat…...

学习第六十五行

仔细观察键盘&#xff0c;会发现一个$符号&#xff0c;其实是有含义的。 在 shell 脚本中&#xff0c;美元符号 $ 有几种重要的含义&#xff1a; 变量引用&#xff1a;$ 用于引用变量的值。例如&#xff0c;如果你有一个变量 name&#xff0c;可以通过 $name 来获取它的值。 n…...

零碎的知识点(七):线性二次调节器(LQR)是什么?

线性二次调节器&#xff08;LQR&#xff09;是什么&#xff1f; 1. LQR的定义与目标2. LQR的原理性能指标 J J J最优解的计算控制律 3. LQR的性质4. 举例说明问题描述解步骤仿真结果 5. 实际应用总结 线性二次调节器&#xff08;LQR&#xff09; 是一种经典的最优控制方法&…...

Matlab一些使用技巧

代码分段 两个百分号就可以实现代码的分段&#xff0c;不同段之间会以不同的背景色显示&#xff0c;方便调试 如下&#xff1a; %% 腐蚀 stlen TimeWidth*Fs/50; %线性算子的长度&#xff0c;1/100的脉宽&#xff0c;对应0.5us&#xff0c;15个采样点 stlen 100; SE strel…...

Linux 发行版介绍与对比:Red Hat、Ubuntu、Kylin、Debian

Linux 操作系统有众多发行版&#xff08;Distros&#xff09;&#xff0c;每个发行版的设计目标、目标用户、应用场景和使用方式有所不同。常见的 Linux 发行版包括 Red Hat、Ubuntu、Kylin 和 Debian。以下是这些发行版的详细介绍与对比&#xff0c;以及它们的应用场景和使用方…...

从CentOS到龙蜥:企业级Linux迁移实践记录(龙蜥开局)

引言&#xff1a; 在我们之前的文章中&#xff0c;我们详细探讨了从CentOS迁移到龙蜥操作系统的基本过程和考虑因素。今天&#xff0c;我们将继续这个系列&#xff0c;重点关注龙蜥系统的实际应用——特别是常用软件的安装和配置。 龙蜥操作系统&#xff08;OpenAnolis&#…...

java1-相对路径与绝对路径

注意注意~开始新部分啦! 开始正式分享java前,先为大家分享一下一个常用的概念---文件的相对路径与绝对路径. 开篇明义: 相对路径是指一个文件或目录相对于当前工作目录的路径。相对路径不包含根目录&#xff0c;而是从当前目录开始计算。 绝对路径是指一个文件或目录从根目录…...

iChainfo 品牌升級為 ichaingo,打造 Web3 數據基礎設施新標杆

Web3 數據基礎設施服務商 iChainfo 今⽇正式宣佈&#xff0c;全新名稱 「ichaingo」 重磅登場&#xff0c;新的官⽅網站 ichaingo.com 正式上線。此次品牌升級基於 Web3 ⾏業的發展趨勢和公司⾃⾝的戰略布局&#xff0c;旨在為全 球⽤戶提供更準確、即時、全⾯、深⼊的 Web3 數…...

Flink概念知识讲解之:Restart重启策略配置

Flink概念知识讲解之&#xff1a;Restart重启策略配置 当 Task 发生故障时&#xff0c;Flink 需要重启出错的 Task 以及其他受到影响的 Task &#xff0c;以使得作业恢复到正常执行状态。 Flink 通过重启策略和故障恢复策略来控制 Task 重启&#xff1a;重启策略决定是否可以…...

[java基础-集合篇]LinkedList源码粗析

LinkedList 的数据结构 实现List、Deque 接口&#xff0c;基于 双向链表实现的列表。与基于数组的 ArrayList 不同&#xff0c;基于链表的LinkedList 允许在列表的任何位置快速地插入和删除元素。 Java中LinkedList实现了Deque&#xff0c;它提供了 add, offer, remove, poll, …...

IDEA运行Tomcat出现乱码问题解决汇总

最近正值期末周&#xff0c;有很多同学在写期末Java web作业时&#xff0c;运行tomcat出现乱码问题&#xff0c;经过多次解决与研究&#xff0c;我做了如下整理&#xff1a; 原因&#xff1a; IDEA本身编码与tomcat的编码与Windows编码不同导致&#xff0c;Windows 系统控制台…...

linux之kylin系统nginx的安装

一、nginx的作用 1.可做高性能的web服务器 直接处理静态资源&#xff08;HTML/CSS/图片等&#xff09;&#xff0c;响应速度远超传统服务器类似apache支持高并发连接 2.反向代理服务器 隐藏后端服务器IP地址&#xff0c;提高安全性 3.负载均衡服务器 支持多种策略分发流量…...

【杂谈】-递归进化:人工智能的自我改进与监管挑战

递归进化&#xff1a;人工智能的自我改进与监管挑战 文章目录 递归进化&#xff1a;人工智能的自我改进与监管挑战1、自我改进型人工智能的崛起2、人工智能如何挑战人类监管&#xff1f;3、确保人工智能受控的策略4、人类在人工智能发展中的角色5、平衡自主性与控制力6、总结与…...

线程同步:确保多线程程序的安全与高效!

全文目录&#xff1a; 开篇语前序前言第一部分&#xff1a;线程同步的概念与问题1.1 线程同步的概念1.2 线程同步的问题1.3 线程同步的解决方案 第二部分&#xff1a;synchronized关键字的使用2.1 使用 synchronized修饰方法2.2 使用 synchronized修饰代码块 第三部分&#xff…...

前端导出带有合并单元格的列表

// 导出async function exportExcel(fileName "共识调整.xlsx") {// 所有数据const exportData await getAllMainData();// 表头内容let fitstTitleList [];const secondTitleList [];allColumns.value.forEach(column > {if (!column.children) {fitstTitleL…...

什么是库存周转?如何用进销存系统提高库存周转率?

你可能听说过这样一句话&#xff1a; “利润不是赚出来的&#xff0c;是管出来的。” 尤其是在制造业、批发零售、电商这类“货堆成山”的行业&#xff0c;很多企业看着销售不错&#xff0c;账上却没钱、利润也不见了&#xff0c;一翻库存才发现&#xff1a; 一堆卖不动的旧货…...

【HTML-16】深入理解HTML中的块元素与行内元素

HTML元素根据其显示特性可以分为两大类&#xff1a;块元素(Block-level Elements)和行内元素(Inline Elements)。理解这两者的区别对于构建良好的网页布局至关重要。本文将全面解析这两种元素的特性、区别以及实际应用场景。 1. 块元素(Block-level Elements) 1.1 基本特性 …...

【Java学习笔记】BigInteger 和 BigDecimal 类

BigInteger 和 BigDecimal 类 二者共有的常见方法 方法功能add加subtract减multiply乘divide除 注意点&#xff1a;传参类型必须是类对象 一、BigInteger 1. 作用&#xff1a;适合保存比较大的整型数 2. 使用说明 创建BigInteger对象 传入字符串 3. 代码示例 import j…...

保姆级教程:在无网络无显卡的Windows电脑的vscode本地部署deepseek

文章目录 1 前言2 部署流程2.1 准备工作2.2 Ollama2.2.1 使用有网络的电脑下载Ollama2.2.2 安装Ollama&#xff08;有网络的电脑&#xff09;2.2.3 安装Ollama&#xff08;无网络的电脑&#xff09;2.2.4 安装验证2.2.5 修改大模型安装位置2.2.6 下载Deepseek模型 2.3 将deepse…...

【Go语言基础【12】】指针:声明、取地址、解引用

文章目录 零、概述&#xff1a;指针 vs. 引用&#xff08;类比其他语言&#xff09;一、指针基础概念二、指针声明与初始化三、指针操作符1. &&#xff1a;取地址&#xff08;拿到内存地址&#xff09;2. *&#xff1a;解引用&#xff08;拿到值&#xff09; 四、空指针&am…...