Maven Pom 文件中的隐式依赖导致Jar冲突

2024-09-05 12:18

本文主要是介绍Maven Pom 文件中的隐式依赖导致Jar冲突,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

<span style="font-family:文泉驿等宽微米黑;font-size:14px;line-height:21px">首先在pom.xml中添加:</span><div><pre name="code" class="prettyprint linenums prettyprinted" style="font-size:13px; font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace; word-wrap:break-word; background-color:rgb(247,247,249); padding:10px; border:1px solid rgb(225,225,232)"><div class="linenums" style="color:rgb(30,52,123); margin-top:0px; margin-bottom:0px; padding-left:0px"><div class="L0" style="color:rgb(190,190,197); line-height:18px; padding-left:0px; list-style-type:none"><code class="language-xml" style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace; word-wrap:break-word"><span class="tag" style="color:#0088;"><reporting></span></code></div><div class="L1" style="color:rgb(190,190,197); line-height:18px; padding-left:0px; list-style-type:none"><code class="language-xml" style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace; word-wrap:break-word"><span class="pln" style="color:#48484c;">	</span><span class="tag" style="color:#0088;"><plugins></span></code></div><div class="L2" style="color:rgb(190,190,197); line-height:18px; padding-left:0px; list-style-type:none"><code class="language-xml" style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace; word-wrap:break-word"><span class="pln" style="color:#48484c;">		</span><span class="tag" style="color:#0088;"><plugin></span></code></div><div class="L3" style="color:rgb(190,190,197); line-height:18px; padding-left:0px; list-style-type:none"><code class="language-xml" style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace; word-wrap:break-word"><span class="pln" style="color:#48484c;">			</span><span class="tag" style="color:#0088;"><groupId></span><span class="pln" style="color:#48484c;">org.apache.maven.plugins</span><span class="tag" style="color:#0088;"></groupId></span></code></div><div class="L4" style="color:rgb(190,190,197); line-height:18px; padding-left:0px; list-style-type:none"><code class="language-xml" style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace; word-wrap:break-word"><span class="pln" style="color:#48484c;">			</span><span class="tag" style="color:#0088;"><artifactId></span><span class="pln" style="color:#48484c;"> maven-project-info-reports-plugin </span><span class="tag" style="color:#0088;"></artifactId></span></code></div><div class="L5" style="color:rgb(190,190,197); line-height:18px; padding-left:0px; list-style-type:none"><code class="language-xml" style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace; word-wrap:break-word"><span class="pln" style="color:#48484c;">		</span><span class="tag" style="color:#0088;"></plugin></span></code></div><div class="L6" style="color:rgb(190,190,197); line-height:18px; padding-left:0px; list-style-type:none"><code class="language-xml" style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace; word-wrap:break-word"><span class="pln" style="color:#48484c;">	</span><span class="tag" style="color:#0088;"></plugins></span></code></div><div class="L7" style="color:rgb(190,190,197); line-height:18px; padding-left:0px; list-style-type:none"><code class="language-xml" style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace; word-wrap:break-word"><span class="tag" style="color:#0088;"></reporting></span></code></div></div>

如果用的是eclipse,那就用run as-build-在Goals那个框框里输入:
project-info-reports:dependencies,如果实在dos环境下,
就mvn project-info-reports:dependencies。然后就会在target的文件夹下,生成一个site文件夹,里边有个dependency.html,进去就能看到详细的依赖的信息。
或者直接在eclipse中打开pom.xml文件
会看到打开的窗口中有一个dependency hie开头的选项卡。
这个选择卡页面<span style="color:#ff0000;">左半部分显示了详细的jar包依赖树</span>。右半部分则是maven将会下载的jar包。
比如我们看到<span style="color:#ff0000;">右半部分</span>有2个asm的jar,版本不同。
现在需要排除其中低版本的jar(比如xwork-core下的某个jar依赖的asm版本相对较低,不一定说是xwork-core依赖,而是它的依赖的依赖,即多重依赖的asm都是可以的)
 
<div><pre name="code" class="prettyprint linenums prettyprinted" style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace; word-wrap:break-word; background-color:rgb(247,247,249); padding:10px; border:1px solid rgb(225,225,232)"><div class="linenums" style="color:rgb(30,52,123); margin-top:0px; margin-bottom:0px; padding-left:0px"><div class="L0" style="color:rgb(190,190,197); line-height:18px; padding-left:0px; list-style-type:none"><code class="language-xml" style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace; word-wrap:break-word"><span class="tag" style="color:#0088;"><dependency></span></code></div><div class="L1" style="color:rgb(190,190,197); line-height:18px; padding-left:0px; list-style-type:none"><code class="language-xml" style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace; word-wrap:break-word"><span class="pln" style="color:#48484c;">	</span><span class="tag" style="color:#0088;"><groupId></span><span class="pln" style="color:#48484c;">org.apache.struts.xwork</span><span class="tag" style="color:#0088;"></groupId></span></code></div><div class="L2" style="color:rgb(190,190,197); line-height:18px; padding-left:0px; list-style-type:none"><code class="language-xml" style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace; word-wrap:break-word"><span class="pln" style="color:#48484c;">	</span><span class="tag" style="color:#0088;"><artifactId></span><span class="pln" style="color:#48484c;">xwork-core</span><span class="tag" style="color:#0088;"></artifactId></span></code></div><div class="L3" style="color:rgb(190,190,197); line-height:18px; padding-left:0px; list-style-type:none"><code class="language-xml" style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace; word-wrap:break-word"><span class="pln" style="color:#48484c;">	</span><span class="tag" style="color:#0088;"><version></span><span class="pln" style="color:#48484c;">${struts.version}</span><span class="tag" style="color:#0088;"></version></span></code></div><div class="L4" style="color:rgb(190,190,197); line-height:18px; padding-left:0px; list-style-type:none"><code class="language-xml" style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace; word-wrap:break-word"><span class="pln" style="color:#48484c;">	</span><span class="tag" style="color:#0088;"><exclusions></span></code></div><div class="L5" style="color:rgb(190,190,197); line-height:18px; padding-left:0px; list-style-type:none"><code class="language-xml" style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace; word-wrap:break-word"><span class="pln" style="color:#48484c;">		</span><span class="tag" style="color:#0088;"><exclusion></span></code></div><div class="L6" style="color:rgb(190,190,197); line-height:18px; padding-left:0px; list-style-type:none"><code class="language-xml" style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace; word-wrap:break-word"><span class="pln" style="color:#48484c;">			</span><span class="tag" style="color:#0088;"><artifactId></span><span class="pln" style="color:#48484c;">asm</span><span class="tag" style="color:#0088;"></artifactId></span></code></div><div class="L7" style="color:rgb(190,190,197); line-height:18px; padding-left:0px; list-style-type:none"><code class="language-xml" style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace; word-wrap:break-word"><span class="pln" style="color:#48484c;">			</span><span class="tag" style="color:#0088;"><groupId></span><span class="pln" style="color:#48484c;">asm</span><span class="tag" style="color:#0088;"></groupId></span></code></div><div class="L8" style="color:rgb(190,190,197); line-height:18px; padding-left:0px; list-style-type:none"><code class="language-xml" style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace; word-wrap:break-word"><span class="pln" style="color:#48484c;">		</span><span class="tag" style="color:#0088;"></exclusion></span></code></div><div class="L9" style="color:rgb(190,190,197); line-height:18px; padding-left:0px; list-style-type:none"><code class="language-xml" style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace; word-wrap:break-word"><span class="pln" style="color:#48484c;">	</span><span class="tag" style="color:#0088;"></exclusions></span></code></div><div class="L0" style="color:rgb(190,190,197); line-height:18px; padding-left:0px; list-style-type:none"><code class="language-xml" style="font-family:Consolas,'Liberation Mono',Menlo,Courier,monospace; word-wrap:break-word"><span class="tag" style="color:#0088;"></dependency></span></code></div></div>
 

以后该如何解决这种类似的问题呢。eclipse提供了对隐式依赖jar包的查看功能:在eclipse中打开一个pom文件,在Dependency Hierarchy的Tab页中,就可以查看当前pom文件中显示声明的jar包,及这些显示声明的jar中隐式引入的依赖jar包。


这样就可以查看有哪些隐式的依赖jar会导致jar包冲突了。

这篇关于Maven Pom 文件中的隐式依赖导致Jar冲突的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1138933

相关文章

Spring Boot循环依赖原理、解决方案与最佳实践(全解析)

《SpringBoot循环依赖原理、解决方案与最佳实践(全解析)》循环依赖指两个或多个Bean相互直接或间接引用,形成闭环依赖关系,:本文主要介绍SpringBoot循环依赖原理、解决方案与最... 目录一、循环依赖的本质与危害1.1 什么是循环依赖?1.2 核心危害二、Spring的三级缓存机制2.1 三

Python如何自动生成环境依赖包requirements

《Python如何自动生成环境依赖包requirements》:本文主要介绍Python如何自动生成环境依赖包requirements问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑... 目录生成当前 python 环境 安装的所有依赖包1、命令2、常见问题只生成当前 项目 的所有依赖包1、

Spring Boot项目部署命令java -jar的各种参数及作用详解

《SpringBoot项目部署命令java-jar的各种参数及作用详解》:本文主要介绍SpringBoot项目部署命令java-jar的各种参数及作用的相关资料,包括设置内存大小、垃圾回收... 目录前言一、基础命令结构二、常见的 Java 命令参数1. 设置内存大小2. 配置垃圾回收器3. 配置线程栈大小

idea maven编译报错Java heap space的解决方法

《ideamaven编译报错Javaheapspace的解决方法》这篇文章主要为大家详细介绍了ideamaven编译报错Javaheapspace的相关解决方法,文中的示例代码讲解详细,感兴趣的... 目录1.增加 Maven 编译的堆内存2. 增加 IntelliJ IDEA 的堆内存3. 优化 Mave

springboot循环依赖问题案例代码及解决办法

《springboot循环依赖问题案例代码及解决办法》在SpringBoot中,如果两个或多个Bean之间存在循环依赖(即BeanA依赖BeanB,而BeanB又依赖BeanA),会导致Spring的... 目录1. 什么是循环依赖?2. 循环依赖的场景案例3. 解决循环依赖的常见方法方法 1:使用 @La

一文教你如何将maven项目转成web项目

《一文教你如何将maven项目转成web项目》在软件开发过程中,有时我们需要将一个普通的Maven项目转换为Web项目,以便能够部署到Web容器中运行,本文将详细介绍如何通过简单的步骤完成这一转换过程... 目录准备工作步骤一:修改​​pom.XML​​1.1 添加​​packaging​​标签1.2 添加

SpringBoot中配置文件pom.xml的使用详解

《SpringBoot中配置文件pom.xml的使用详解》SpringBoot的pom.xml文件是Maven项目的核心配置文件,用于定义项目的依赖、插件、构建配置等信息,下面小编就来和大家详细介绍一... 目录1. 基本结构2. 关键部分详解2.1 <modelVersion>2.2 项目坐标2.3 <p

使用mvn deploy命令上传jar包的实现

《使用mvndeploy命令上传jar包的实现》本文介绍了使用mvndeploy:deploy-file命令将本地仓库中的JAR包重新发布到Maven私服,文中通过示例代码介绍的非常详细,对大家的学... 目录一、背景二、环境三、配置nexus上传账号四、执行deploy命令上传包1. 首先需要把本地仓中要

Maven pom.xml文件中build,plugin标签的使用小结

《Mavenpom.xml文件中build,plugin标签的使用小结》本文主要介绍了Mavenpom.xml文件中build,plugin标签的使用小结,文中通过示例代码介绍的非常详细,对大家的学... 目录<build> 标签Plugins插件<build> 标签<build> 标签是 pom.XML

MySQL的隐式锁(Implicit Lock)原理实现

《MySQL的隐式锁(ImplicitLock)原理实现》MySQL的InnoDB存储引擎中隐式锁是一种自动管理的锁,用于保证事务在行级别操作时的数据一致性和安全性,本文主要介绍了MySQL的隐式锁... 目录1. 背景:什么是隐式锁?2. 隐式锁的工作原理3. 隐式锁的类型4. 隐式锁的实现与源代码分析4