maven工程指定依赖打成一个jar包
花个一个小时各种查资料终于搞定了。。翻墙各种搜,还是没有找到解决方案,最后在maven官网发现了shade插件,查阅使用方法,终于搞定!
pom配置
<profiles>
<profile>
<id>shade-jar</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<configuration>
<!-- put your configurations here -->
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>groupId:artifactId</include>
</includes>
<!--excludes>
<exclude>groupId:artifactId</exclude>
</excludes-->
</artifactSet>
<filters>
<filter>
<artifact>com.unisound.dcs:*</artifact>
<excludes>
<exclude>**/*.xml</exclude>
<exclude>**/*.properties</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
执行命令:mvn clean package -DskipTests -Pshade-jar
打开工程下的target目录、结构如下:
我的工程为data-cloud-service-client,我们所需要的jar为data-cloud-service-client-2.0.7-SNAPSHOT.jar
此jar包包括了我们配置的里面include的两个jar包的class文件,注意:配置了includes则不必配置excludes,两着二选一,includes会将我们指定的依赖打入到jar中,未指定的会excludes。filters节点是指我们可以配置includes或者excludes依赖包里的指定文件。配置支持通配符,**/*.xml
指忽略所有文件夹下的以xml结尾的文件。