赞
踩
项目同时引入了easy excel和自动化测试框架concordion-excel-extension,这两个依赖都制定了内置了POI版本,我的冲突是POI3.14和4.1.2,导致了在easy excel使用时依赖混论,找不到方法。报错:
- Caused by: java.lang. NoClassDefFoundError: org/apache/poi/util/IOUtils
-
- Caused by: java. lang. NoSuchMethodError: org.apache.poi.util.Ioutils.peekrirstNBytes (Ljava/io/Input Stream;I
-
- com.alibaba.excel.exception.ExcelAnalysisException:java.lang.NoSuchMethodError:org.apache.poi.util.IOUtils.peekFirstNBytes
其实就是两个POI提供的方法不一样,当依赖混乱时就会找不到对应版本的对应方法
这种方案的前提是必须保留两个POI版本,因为各自依赖不同。如果可以去掉一个提升版本依赖是最好的,如果不能的情况下那只能找到中间版本,但这样又会增加一个版本依赖。例如我的冲突时3.14和4.12那么中间版本就是POI3.16
-
- <dependency>
- <groupId>org.apache.poi</groupId>
- <artifactId>poi</artifactId>
- <version>3.16</version>
- </dependency>
-
- <dependency>
- <groupId>org.apache.poi</groupId>
- <artifactId>poi-ooxml</artifactId>
- <version>3.16</version>
- </dependency>
- <dependency>
- <groupId>org.apache.poi</groupId>
- <artifactId>poi-ooxml-schemas</artifactId>
- <version>3.16</version>
- </dependency>
可以将easy excel源代码克隆,官网提供了各个版本的代码,克隆下来之后。将easy excel所依赖的POI版本重新打包,也就是起别名。这样的话隔离性好,同时可以管理自由maven。具体实现方式如下:
rule org.apache.poi.** com.customize.poi.@1
- 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包
- 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
- <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>
mvn clean install -DkispTests=true
- <dependency>
- <groupId>com.customize</groupId>
- <artifactId>easyexcel</artifactId>
- <version>2.2.6</version>
- </dependency>
- <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>
方案一是一个大佬想到的,这里无法提名
方案二参考文章:
比我写的要详尽很多,有不懂的可以看看这个
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。