spring - 为了避免 jar handler/spring在合并多个 spring 依赖项时被覆盖,在单个Maven 程序集插件的思想中,可以避免这种情况

  显示原文与译文双语对照的内容
119 4

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

因为其他人在 forum.springsource.org 线程上发现 spotted spotted在不同 jars 中出现的文件 META-INF/spring.handlersMETA-INF/spring.schemas occurs在单个文件中的maven-assembly-plugin repackages被覆盖时被覆盖。

查看两个spring-*文件的内容,你可以看到文件位于同一个位置相对于类路径的位置

$ 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 文件夹放入特定的软件包中?如果是这样,我建议( 希望它适用) 是将 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 中合并时它们不会冲突。你觉得怎么样?

时间:原作者:0个回答

148 3

我使用着色器插件替代了 Bug,而不是( 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>

我想我在springsource论坛上找到了解决方案。自从我查找它以来,已经有相当长的时间。无法真正记住作者。他也是这样的:p

cheers!

原作者:
67 5

使用 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>
原作者:
...