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

来源:互联网 发布:淘宝刷到单被骗咋追回 编辑:程序博客网 时间:2024/05/21 09:42

<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包冲突了。
0 0
原创粉丝点击