由于业务需要,引入easyExcel。easyExcel最低依赖版本是3.17,系统中已经存在3.9版本,排除依赖有些类无法找到,导致jar包冲突无法共存。寻求解决方案时,实践可通过修改jar包路径达到目的。在此对过程做一下记录。
一、重新打包poi
1.准备好需要的资源
2.创建rule.txt
3.rule.txt中写入文本
rule org.apache.poi.** com.customize.poi.@1
3.验证能否修改包名
3.17可以忽略,实践通过,详细用法可自行研究
java -jar jarjar-1.3.jar strings poi-3.17.jar
4.重新打包
自行修改规则
java -jar jarjar-1.3.jar process rule.txt poi-3.17.jar customize-poi-3.17.jar java -jar jarjar-1.3.jar process rule.txt poi-ooxml-3.17.jar customize-poi-ooxml-3.17.jar java -jar jarjar-1.3.jar process rule.txt poi-ooxml-schemas-3.17.jar customize-poi-schemas-3.17.jar
生成新的jar包
5.打包到本地仓库
mvn install:install-file -Dfile=customize-poi-3.17.jar -DgroupId=com.customize -DartifactId=poi -Dversion=3.17 -Dpackaging=jar mvn install:install-file -Dfile=customize-poi-ooxml-3.17.jar -DgroupId=com.customize -DartifactId=poi-ooxml -Dversion=3.17 -Dpackaging=jar mvn install:install-file -Dfile=customize-poi-schemas-3.17.jar -DgroupId=com.customize -DartifactId=poi-ooxml-schemas -Dversion=3.17 -Dpackaging=jar
打包后
二、重新编译easyExcel
1.下载easyExcel源码
注意easyExcel版本,导入IDE(笔者使用IDEA)
或者
git clone https://github.com/alibaba/easyexcel.git git checkout -b dev2.2.6 v2.2.6
2.修改pom文件中poi依赖
<dependency> <groupId>com.customize</groupId> <artifactId>poi</artifactId> <version>3.17</version> </dependency> <dependency> <groupId>com.customize</groupId> <artifactId>poi-ooxml</artifactId> <version>3.17</version> </dependency> <dependency> <groupId>com.customize</groupId> <artifactId>poi-ooxml-schemas</artifactId> <version>3.17</version> </dependency>
修改项目坐标
<groupId>com.customize</groupId> <artifactId>easyexcel</artifactId> <version>2.2.6</version> <packaging>jar</packaging> <name>easyexcel</name>
3.全局替换import
4.编译
mvn clean install -Dmaven.test.skip=true
编译失败
加入依赖
<dependency> <groupId>org.apache.xmlbeans</groupId> <artifactId>xmlbeans</artifactId> <version>2.3.0</version> </dependency>
重新编译
三.使用
1.项目中添加依赖
此时easyExcel依赖为修改后的,可传至私服/安装到本地仓库
<dependency> <groupId>com.customize</groupId> <artifactId>easyexcel</artifactId> <version>2.2.6</version> </dependency>
依赖的pom
<dependency> <groupId>com.customize</groupId> <artifactId>poi</artifactId> <version>3.17</version> </dependency> <dependency> <groupId>com.customize</groupId> <artifactId>poi-ooxml</artifactId> <version>3.17</version> </dependency> <dependency> <groupId>com.customize</groupId> <artifactId>poi-ooxml-schemas</artifactId> <version>3.17</version> </dependency>
其余依赖(按需添加,可能已经存在,参考easyexcel原pom文件)
<dependency> <groupId>cglib</groupId> <artifactId>cglib</artifactId> <version>3.1</version> </dependency> <dependency> <groupId>org.ehcache</groupId> <artifactId>ehcache</artifactId> <version>3.4.0</version> </dependency>
转载地址:https://blog.csdn.net/u012399690/article/details/109511257