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

相关文章

Python pip下载包及所有依赖到指定文件夹的步骤说明

《Pythonpip下载包及所有依赖到指定文件夹的步骤说明》为了方便开发和部署,我们常常需要将Python项目所依赖的第三方包导出到本地文件夹中,:本文主要介绍Pythonpip下载包及所有依... 目录步骤说明命令格式示例参数说明离线安装方法注意事项总结要使用pip下载包及其所有依赖到指定文件夹,请按照以

Maven 配置中的 <mirror>绕过 HTTP 阻断机制的方法

《Maven配置中的<mirror>绕过HTTP阻断机制的方法》:本文主要介绍Maven配置中的<mirror>绕过HTTP阻断机制的方法,本文给大家分享问题原因及解决方案,感兴趣的朋友一... 目录一、问题场景:升级 Maven 后构建失败二、解决方案:通过 <mirror> 配置覆盖默认行为1. 配置示

maven私服配置全过程

《maven私服配置全过程》:本文主要介绍maven私服配置全过程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录使用Nexus作为 公司maven私服maven 私服setttings配置maven项目 pom配置测试效果总结使用Nexus作为 公司maven私

MySQL版本问题导致项目无法启动问题的解决方案

《MySQL版本问题导致项目无法启动问题的解决方案》本文记录了一次因MySQL版本不一致导致项目启动失败的经历,详细解析了连接错误的原因,并提供了两种解决方案:调整连接字符串禁用SSL或统一MySQL... 目录本地项目启动报错报错原因:解决方案第一个:第二种:容器启动mysql的坑两种修改时区的方法:本地

IDEA如何实现远程断点调试jar包

《IDEA如何实现远程断点调试jar包》:本文主要介绍IDEA如何实现远程断点调试jar包的问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录问题步骤总结问题以jar包的形式运行Spring Boot项目时报错,但是在IDEA开发环境javascript下编译

Java -jar命令如何运行外部依赖JAR包

《Java-jar命令如何运行外部依赖JAR包》在Java应用部署中,java-jar命令是启动可执行JAR包的标准方式,但当应用需要依赖外部JAR文件时,直接使用java-jar会面临类加载困... 目录引言:外部依赖JAR的必要性一、问题本质:类加载机制的限制1. Java -jar的默认行为2. 类加

IDEA中Maven Dependencies出现红色波浪线的原因及解决方法

《IDEA中MavenDependencies出现红色波浪线的原因及解决方法》在使用IntelliJIDEA开发Java项目时,尤其是基于Maven的项目,您可能会遇到MavenDependenci... 目录一、问题概述二、解决步骤2.1 检查 Maven 配置2.2 更新 Maven 项目2.3 清理本

java -jar命令运行 jar包时运行外部依赖jar包的场景分析

《java-jar命令运行jar包时运行外部依赖jar包的场景分析》:本文主要介绍java-jar命令运行jar包时运行外部依赖jar包的场景分析,本文给大家介绍的非常详细,对大家的学习或工作... 目录Java -jar命令运行 jar包时如何运行外部依赖jar包场景:解决:方法一、启动参数添加: -Xb

maven中的maven-antrun-plugin插件示例详解

《maven中的maven-antrun-plugin插件示例详解》maven-antrun-plugin是Maven生态中一个强大的工具,尤其适合需要复用Ant脚本或实现复杂构建逻辑的场景... 目录1. 核心功能2. 典型使用场景3. 配置示例4. 关键配置项5. 优缺点分析6. 最佳实践7. 常见问题

windows系统上如何进行maven安装和配置方式

《windows系统上如何进行maven安装和配置方式》:本文主要介绍windows系统上如何进行maven安装和配置方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不... 目录1. Maven 简介2. maven的下载与安装2.1 下载 Maven2.2 Maven安装2.