施用 maven shade plugin 解决 jar 或类的多版本冲突
施用 maven shade plugin 解决 jar 或类的多版本冲突
java 应用经常会碰到的依赖的三方库出现版本冲突,下面举一个具体的例子。
Dubbo 是一个分布式的服务框架,其中的一种 rpc 实现(dubbo 协议)使用 hessian 3.2.0 来做序列化,另外一种实现(hsf协议)同样使用了 hesssian,但使用的版本是 3.0.14。如果现在一个应用中同时使用了 dubbo 协议和 hsf 协议,这个时候应用使用哪个版本的 hessian 呢?使用 3.2.0 可能会影响 hsf 协议,如果使用 3.0.14 那么 dubbo 协议会受影响。
maven shade plugin 能够把项目中依赖的 jar 包中的一些类文件打包到项目构建生成的 jar 包中,在打包的时候它有一个非常重要的特性是支持 relocation。relocation 的意思是把类重命名,比如把 com.caucho.hessian.io.HessianInput 重命名为 hidden.com.caucho.hessian.io.HessianInput,这样就不会出现冲突了。
下面是项目中 shade 插件的配置。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.7.</version>
<executions>
<execution>
<id>shade-hessian</id>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>hessian:hessian</include>
</includes>
</artifactSet>
<createSourcesJar>true</createSourcesJar>
<relocations>
<relocation>
<pattern>com.caucho</pattern>
<shadedPattern>com.alibaba.dubbo.hsf.hessian.v3_0_14_bugfix</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
上面的配置把 groupId 为 hessian artifactId 也为 hessian 的依赖中 com.caucho 包下面的所有类重命名为 com.alibaba.dubbo.hsf.hessian.v3_0_14_bugfix 后和项目中的类文件一起打到 jar 包中。
maven 2 就是通过这种方式打包的,可以看一下 maven 2 安装目录下 lib 目录中的那个 jar。
施用 maven shade plugin 解决 jar 或类的多版本冲突的更多相关文章
- [Apache Maven Shade Plugin] [example] [001] 官方例子:includes-excludes
链接地址:[Selecting Contents for Uber JAR](http://maven.apache.org/plugins/maven-shade-plugin/examples/i ...
- 解决 .net core 中 nuget 包版本冲突问题
今天在一个 asp.net core 项目中遇到了 nuget 包版本冲突的问题,错误信息如下: Version conflict detected for Microsoft.AspNet.WebA ...
- 解决 .net core 中 nuget 包版本冲突问题[转载]
今天在一个 asp.net core 项目中遇到了 nuget 包版本冲突的问题,错误信息如下: Version conflict detected for Microsoft.AspNet.WebA ...
- maven shade插件小记
maven shade plugin插件小用 项目中一直使用assembly插件来整合依赖包到一个胖jar,在做这个akka http项目的时候,在scala ide的run/debug中都执行正常, ...
- 记录一次maven打包时将test目录下的类打包到jar中,Maven Assembly Plugin的使用
今天有人问我打包后找不到主类,运行的类写在test中.按照常规,test目录下的文件不会打包到jar包中.(但是我测试一个springboot工程就可以,这里之后再研究) 具体解决如下 第一步:在po ...
- maven 解决jar包冲突及简单使用
maven 解决jar包冲突 1.jar包冲突原因 maven中使用坐标导入jar包时会把与之相关的依赖jar包导入(导入spring-context的jar时就会把spring的整个主体导入) ,而 ...
- 如何解决Maven和SBT下载Jar包太慢
国内:如何解决Maven和SBT下载Jar包太慢 Maven 远程仓库 <mirror> <id>ui</id> <mirrorOf>central&l ...
- [Maven] - Eclipse "maven compiler plugin" 冲突解决
刚安装最新的Maven 3.2.5,在eclipse中使用maven的Run As->Maven Install,总会提示: Failed to execute goal org.apache. ...
- Maven 解决JAR包冲突
在JAR 冲突的情况下, 利用Eclipse方式解决JAR包冲突时比较方便简洁的,步骤如下 1. 在Eclipse 中打开pom.xml , 选择 “Dependency Hierarchy” 2 ...
随机推荐
- Android经常使用UI组件 - TextView
TextView是Android里面用的最多的UI组件,一般使用在须要显示一些信息的时候,其不能输入,仅仅能初始设定或者在程序中改动. 实例:TextViewDemo 执行效果: 代码清单: 布局文件 ...
- OpenStack导入镜像后Launch不起来的几个问题
Dashboard上显示state为error 没有其他报错 用nova list找到虚拟机的id 然后nova show,可以得到fault详细信息 也可以查看下面两个log /var/log/no ...
- Android,机器狗应用
源码如下: package com.wyl.jqr; import java.io.BufferedReader; import java.io.IOException; import java.io ...
- 触发器应用 trigger
首先有一张表: create table T_SALARY ( name VARCHAR2(20), age NUMBER(2), salary NUMBER(5) ); insert into t_ ...
- (Problem 3)Largest prime factor
The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 60085 ...
- DE1-SOC连接设定
将电源供应器插上电源接口. 使用白色的USB Type B线材将计算机与DE1-SoC上的USB-Blaster II接口连接.此接口主要负责FPGA配置以及HPS Debug使用. 使用Mini-U ...
- partial_sort_百度百科
partial_sort_百度百科 partial_sort
- poj 3368 Frequent values(段树)
Frequent values Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 13516 Accepted: 4971 ...
- 富文本编辑器 - wangEditor 上传图片
效果: . 项目结构图: wangEditor-upload-img.html代码: <html> <head> <title>wangEditor-图片上传< ...
- InheritableThreadLocal
InheritableThreadLocal继承自ThreadLocal,但比ThreadLocal多一个特性: 子线程可以继承父亲线程上下文中的信息 但是,有两个点需要注意的: 只有子线程创建之前的 ...