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 中合併時它們不會衝突。 你覺得怎麼樣?

时间: 原作者:

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>



原作者:
...