maven指定依赖打成一个jar包

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结尾的文件。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值