1、 将第三方依赖性jar包中的文件打包入jar中,打包时修改引入jar包的包名,防止包冲突
<!--将第三方依赖性jar包中的文件打包入jar中-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<!-- 打包失败可能是版本太低,提高版本 -->
<version>3.1.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<!-- 打包时修改引入jar包的包名,防止包冲突 -->
<relocations>
<relocation>
<pattern>org.apache.http</pattern>
<shadedPattern>shaded.org.apache.http</shadedPattern>
<!--<excludes>-->
<!--<exclude>org.codehaus.plexus.util.xml.Xpp3Dom</exclude>-->
<!--<exclude>org.codehaus.plexus.util.xml.pull.*</exclude>-->
<!--</excludes>-->
</relocation>
</relocations>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
2、阻止第三方jar包被打入执行包
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-client</artifactId>
<version>2.7.2</version>
<!-- 阻止第三方jar包被打入执行包 -->
<scope>provided</scope>
</dependency>
3、打包时不包含该包下的部分子包
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>6.3.2</version>
<!-- 不包含org.apache.httpcomponents包 -->
<exclusions>
<exclusion>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
</exclusion>
</exclusions>
</dependency>