嗨,我在我的项目中使用了两个版本的Apache POI jar。因此,我尝试使用maven shaded插件对一个具有所有依赖项的jar进行着色。但是,当我构建项目时,它的构建就成功了,但是当我在代码中导入阴影罐子时,它显示的错误(阴影罐子内的所有方法)都没有找到。有人可以帮我创建阴影罐子的兴趣点吗?
下面是我用来创建带阴影的Apache POI的POM.xml
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.divas</groupId>
<artifactId>poi-conflicting-jarsfix</artifactId>
<version>1.0-SNAPSHOT</version>
<build>
<sourceDirectory>src/main/scala</sourceDirectory>
<testSourceDirectory>src/test/scala</testSourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.apache</mainClass>
</transformer>
</transformers>
<filters>
<filter>
<artifact>*:*</artifact>
<!-- <includes> <include>com.hierynomus.**</include> <include>net.engio.**</include>
<include>org.bouncycastle.**</include> </includes> -->
<excludes>
<exclude>META-INF/maven/**</exclude>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
<relocations>
<relocation>
<pattern></pattern>
<shadedPattern>shaded.</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<artifactId>poi</artifactId>
<version>4.0.0</version>
<groupId>org.apache.poi</groupId>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-examples</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-excelant</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-scratchpad</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.10</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.2</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>
</project>
创建了这个有阴影的jar之后,我在项目pom.xml中添加了以下依赖项
<dependency>
<groupId>com.divas</groupId>
<artifactId>poi-conflicting-jarsfix</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
添加以下依赖项后,我将在行
下导入import shaded.org.apache.poi.ss.usermodel.Workbook
代替
import org.apache.poi.ss.usermodel.Workbook
但是我的代码抛出了异常,称为Workbook并不是shaded.org.apache.poi.ss.usermodel的成员
但是在没有阴影罐子的情况下运行良好