Maven 打包可运行Jar

解决Spring依赖冲突
本文介绍了解决使用Spring框架打包时遇到的依赖冲突问题,通过使用maven-shade-plugin插件来合并而非覆盖关键配置文件,避免了spring.handlers和spring.schemas文件被覆盖导致的错误。
本项目用到了Spring所以打包时需要将Spring的依赖都要加上。

      1. 用Assembly插件时,系统爆出

unable to locate spring namespacehandler.

查询资料说在导出时多个spring文件相互覆盖了spring.handlers,spring.schemas,spring.tooling引起的,所以我们要做的就是合并这些配置文件,而不是覆盖他们。

2. 解决办法,用maven-shade-plugin



              org.apache.maven.plugins
              maven-shade-plugin
              2.1
             
                     
                              package
                             
                                      shade
                             
                             
                                             
                                                       
                                                              META-INF/spring.handlers
                                                     
                                                     
                                                              META-INF/spring.schemas
                                                     
                                                     
                                                              com.wushi.myquartz.TestQuartZ
                                                     
                                             
                             
                     
             
         


3. shade插件注意要用适当的版本,刚开始用2.1版本,老时报Noclassfound Dependency Node, 后来用2.1版本就好了。

Maven官方的解释如下:

AetherClassNotFound

Skip to end of metadata
Go to start of metadata
java.lang.NoClassDefFoundError: org/sonatype/aether/*
Caused by: java.lang.ClassNotFoundException: org.sonatype.aether.*

This error is caused by Maven 3.1-alpha-1 migration from Sonatype Aether to Eclipse Aether (MNG-5354), which is an incompatible change for some plugins.

To support this change, new versions of the affected plugins have been published which work both with Maven 3.0.x and 3.1.x:

groupId

artifactId

affected goal

Plugin Name

Compatible Version

Related Issues

com.google.appengine

appengine-maven-plugin

 

Google AppEngine Maven Plugin

1.8.3 (Maven 3.1.x required)

#31

org.apache.maven.plugins

maven-dependency-plugin

tree

Maven Dependency Plugin

2.8

MDEP-407

org.apache.maven.plugins

maven-enforcer-plugin

 

Maven Enforcer Plugin

1.3

 

org.apache.maven.plugins

maven-project-info-reports-plugin

dependencies

Maven Project Info Reports Plugin

2.7

MPIR-272

org.apache.maven.plugins

maven-shade-plugin

shade

Maven Shade Plugin

2.1

MSHADE-143

org.apache.maven.plugins

maven-site-plugin

site

Maven Site Plugin

3.3

MSITE-683

org.codehaus.mojo

nbm-maven-plugin

 

NetBeans Module plugin

3.11

MNBMODULE-215

org.codehaus.mojo

sonar-maven-plugin

sonar

Sonar Maven Plugin

2.1

MSONAR-22

org.eclipse.tycho

 

 

Tycho

0.18.1

406056

org.twdata.maven

mojo-executor

All the library

mojo-executor

2.1.0

#13



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值