以前一直使用assembly对项目打包,今天因为项目需求多添加了一个spring-tx的引用,结果打包之后启动总是报错:
Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/batch]
更换spring版本,各种clean,install都不行,最后发现是assembly插件打包时的一个缺陷,遇到重名的文件它只会打第一个,后面的都不会打包,所以META-INF/spring.handler和META-INF/spring.schema这两个文件在打包时出错了,只好更换了新的shade插件重新打包才成功。
贴一下shade的配置
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass></mainClass>
</transformer>
<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>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
网友评论