mvn assembly package jar 无法运行

13 篇文章 0 订阅
3 篇文章 0 订阅

       项目中要跑了一个jar工程,每天做一次数据结算。最开始我用的maven-assembly-plugin 打包,发现没什么问题。因为工程中引入了spring,有一处代码需要添加事务,所以就在application中引入了tx。再次打包,运行,提示tx schema 无法加载。百度了一下,因为spring  jar中包含了meta/spring.schema 和 spring.handlers,工程启动会通过存在的配置加载命名空间,但是和我需要的却不是一个版本,所以就会找不到对应的命名空间。 

      又是再次百度,找到了maven-shade-plugin ,到官网看了一下它的使用方式,mvn package 就可以了。

看了一下example ,发现竟然有这样一段配置

    Some jars contain additional resources (such as properties files) that have the same file name. To avoid overwriting, you can opt to merge them by appending their content into one file. One good example for this is when aggregating both the spring-context and plexus-spring jars. Both of them have the META-INF/spring.handlers file which is used by Spring to handle XML schema namespaces. You can merge the contents of all the files with that specific name using the AppendingTransformer as shown below:

 

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>2.3</version>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
            <configuration>
              <transformers>
                <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                  <resource>META-INF/spring.handlers</resource>
                </transformer>
                <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                  <resource>META-INF/spring.schemas</resource>
                </transformer>
              </transformers>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  ...
</project>

   
    英文注释 和我百度的解释类似 ,直接copy到了工程pom.xml 中 mvn package 然后java -jar  *.jar  运行正常
   

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值