easyexcel中poi

陈旧的项目导出excel时用的POI3.14,现在引入easyexcel2.2.6,报错。

Caused by: java.lang.NoClassDefFoundError: org/apache/poi/util/DefaultTempFileCreationStrategy
 at com.alibaba.excel.util.FileUtils.createPoiFilesDirectory(FileUtils.java:138)
 at com.alibaba.excel.write.ExcelBuilderImpl.(ExcelBuilderImpl.java:30)
 at com.alibaba.excel.ExcelWriter.(ExcelWriter.java:47)
 at com.alibaba.excel.write.builder.ExcelWriterBuilder.build(ExcelWriterBuilder.java:130)
 at com.alibaba.excel.write.builder.ExcelWriterBuilder.sheet(ExcelWriterBuilder.java:146)
 at com.alibaba.excel.write.builder.ExcelWriterBuilder.sheet(ExcelWriterBuilder.java:134)

easyexcel依赖POI3.17+,POI版本冲突。POI3.14之前用的地方很多,提升版本代价太大。

现使用maven-shade-plugin来保证POI多版本共存。原理是将POI3.17中的类换一个包名,从而和POI3.14中的类区分开。

  1. 重新编译easyexcel源码包,使用maven-shade-plugin替换poi包名

  2. 将打好的easyexcel.jar放入项目中,添加到本地依赖

    项目中也用到了asm3.3.1,easyexcel引用了asm4.2,也将asm包名替换

    
    
        
            
                org.apache.maven.plugins
                maven-shade-plugin
                3.2.4
                
                    
                        package
                        
                            shade
                        
                        
                            true
                            
                                
                                    
                                    org.apache.poi
                                    shade.org.apache.poi
                                
                                
                                    org.objectweb.asm
                                    shade.org.objectweb.asm
                                
                            
                        
                    
                
            
        
    
    
    
    
    
    
        com.alibaba
        easyexcel
        2.2.6
        ${basedir}/src/main/webapp/WEB-INF/lib/easyexcel-2.2.6.jar
        system
    
    

你可能感兴趣的:(easyexcel中poi)