maven使用assembly打独立可执行jar包启动时报错(关于spring错误的解决方法)

错误如下:Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace

原因assembly的一个bug.参见:http://jira.codehaus.org/browse/MASSEMBLY-360 原因是spring的多个jar包中都含有spring.handlers和spring.schemas文件,而assembly只会把第一次遇到的文件打入jar包,后面遇到的都会skip掉。

解决方法:使用shade插件来打包.在shade的打包配制中指明spring.handlers和spring.schemas文件会以append方式加入进来,从而确保其他spring的jar中的这两个文件的信息不会被遗漏。下面是一份配置的例子:

 

Xml代码   收藏代码
  1. <plugin>  
  2.                 <groupId>org.apache.maven.plugins</groupId>  
  3.                 <artifactId>maven-shade-plugin</artifactId>  
  4.                 <version>1.4</version>  
  5.                 <executions>  
  6.                     <execution>  
  7.                         <phase>package</phase>  
  8.                         <goals>  
  9.                             <goal>shade</goal>  
  10.                         </goals>  
  11.                         <configuration>  
  12.                             <transformers>  
  13.                                 <transformer  
  14.                                         implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">  
  15.                                     <resource>META-INF/spring.handlers</resource>  
  16.                                 </transformer>  
  17.                                 <transformer  
  18.                                         implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">  
  19.                                     <mainClass>com.ddmap.hadoop.db.mongodb.CopyToLocal</mainClass>  
  20.                                 </transformer>  
  21.                                 <transformer  
  22.                                         implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">  
  23.                                     <resource>META-INF/spring.schemas</resource>  
  24.                                 </transformer>  
  25.                             </transformers>  
  26.                         </configuration>  
  27.                     </execution>  
  28.                 </executions>  
  29.             </plugin>  

 

你可能感兴趣的:(assembly)