想法,以避免spring.handlers / spring.schemas合并在一个jar中的多个弹簧依赖关系时被覆盖

我得到的错误Unable to locate NamespaceHandler when using context:annotation-config运行(java -jar)由maven-assembly-plugin组装并包含我的项目及其所有依赖项的jar。

正如其他人正确地在forum.springsource.org 线程(消息#7/8)上发现了问题,因为存在于不同jar中的文件META-INF/spring.handlersMETA-INF/spring.schemas被覆盖当maven-assembly-plugin将jar包重新打包成一个文件时。

查看两个spring – *。jar文件的内容,可以看到文件与classpath相对应的位置相同

 $ jar tf spring-oxm-3.0.3.RELEASE.jar META-INF/spring.handlers META-INF/spring.schemas org/springframework/oxm/GenericMarshaller.class ... $ jar tf spring-context-3.0.3.RELEASE.jar META-INF/spring.handlers META-INF/spring.schemas org/springframework/context/ApplicationContext.class 

是不是可以将META-INF文件夹放在特定的包中? 如果是这样的想法,我会build议,(希望它适用)是把META-INF/spring.shemasMETA-INF/spring.handlers文件放在它们引用的包下。

 $ jar tf spring-oxm-3.0.3.RELEASE.jar org/springframework/oxm/META-INF/spring.schemas org/springframework/oxm/META-INF/spring.handlers org/springframework/oxm/GenericMarshaller.class ... $ jar tf spring-context-3.0.3.RELEASE.jar org/springframework/context/META-INF/spring.handlers org/springframework/context/META-INF/spring.schemas org/springframework/context/ApplicationContext.class 

这样,它们在单个jar中合并时不会发生冲突。 你怎么看待这件事?

我设法摆脱使用着色器插件而不是(buggy)汇编程序插件的错误:

  <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <transformers> <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> <mainClass>at.seresunit.lecturemanager_connector.App</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> </configuration> </execution> </executions> </plugin> 

我认为我在springource论坛上find了解决scheme..从我查阅起来已经有相当长的一段时间了..不能真正记住作者。 无论如何,他的荣誉:第

干杯

用ant。

 <!--define couple of properties to identify spring jar files--> <property name="spring-beans-jar" value="spring-beans-4.0.5.RELEASE.jar"/> <property name="spring-context-jar" value="spring-context-4.0.5.RELEASE.jar"/> <!--other properties--> <target name="dist" depends="compile" description="Prepare distribution"> <!--dump spring-context into build classes (or some place else)--> <unjar src="${lib.dir}/${spring-context-jar}" dest="${build.classes.dir}"/> <!--dump spring-beans on top of it overwriting META-INF/spring.* files--> <unjar src="${lib.dir}/${spring-beans-jar}" dest="${build.classes.dir}"/> <!--get overwritten META-INF/spring.* files of spring-context to some other place--> <unjar src="${lib.dir}/${spring-context-jar}" dest="${build.tmp.dir}"> <patternset> <include name="META-INF/spring.handlers"/> <include name="META-INF/spring.schemas"/> <include name="META-INF/spring.tooling"/> </patternset> </unjar> <!--skipped spring-beans/META-INF/spring.factories as its not present in spring-context--> <!--handled only spring-context and spring-beans as that's what I needed at this point--> <!--append content from spring-context/META-INF/spring.* files--> <concat destfile="${build.classes.dir}/META-INF/spring.handlers" append="true"> <filelist dir="${build.tmp.dir}" files="META-INF/spring.handlers"/> </concat> <concat destfile="${build.classes.dir}/META-INF/spring.schemas" append="true"> <filelist dir="${build.tmp.dir}" files="META-INF/spring.schemas"/> </concat> <concat destfile="${build.classes.dir}/META-INF/spring.tooling" append="true"> <filelist dir="${build.tmp.dir}" files="META-INF/spring.tooling"/> </concat> <jar destfile="${build.dist.dir}/application.jar"> <fileset dir="${build.classes.dir}"/> <!--include all .jar files except already extracted ones--> <zipgroupfileset dir="${lib.dir}" includes="*.jar" excludes="${spring-beans-jar}, ${spring-context-jar}"/> <manifest> <attribute name="Main-Class" value="${main-class}"/> </manifest> </jar> </target>