Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
避免在单个jar中合并多个spring依赖项时覆盖spring.handlers/spring.schemas的想法_Spring_Maven Assembly Plugin_Meta Inf - Fatal编程技术网

避免在单个jar中合并多个spring依赖项时覆盖spring.handlers/spring.schemas的想法

避免在单个jar中合并多个spring依赖项时覆盖spring.handlers/spring.schemas的想法,spring,maven-assembly-plugin,meta-inf,Spring,Maven Assembly Plugin,Meta Inf,当使用context:annotation config运行(java-jar)一个由maven assembly插件组装并包含我的项目及其所有依赖项的jar时,我遇到了一个错误无法定位NamespaceHandler 正如其他人在forum.springsource.org上正确发现的那样,出现问题的原因是不同JAR中存在的文件META-INF/spring.handlers和META-INF/spring.schemas,当maven assembly插件在单个文件中重新打包JAR时,这些文

当使用context:annotation config运行(java-jar)一个由maven assembly插件组装并包含我的项目及其所有依赖项的jar时,我遇到了一个错误
无法定位NamespaceHandler

正如其他人在forum.springsource.org上正确发现的那样,出现问题的原因是不同JAR中存在的文件
META-INF/spring.handlers
META-INF/spring.schemas
,当maven assembly插件在单个文件中重新打包JAR时,这些文件会被覆盖

查看两个spring-*.jar文件的内容,您可以看到这些文件相对于类路径位于相同的位置

$ 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.shemas
META-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中时,它们不会发生冲突。您对此有何看法?

我使用着色器插件而不是(有bug的)汇编程序插件成功地消除了这个bug:

        <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>

org.apache.maven.plugins
maven阴影插件
包裹
阴凉处
at.seresunit.讲师管理器_connector.App
META-INF/spring.handlers
META-INF/spring.schemas
我想我在springsource论坛上找到了解决方案。。我已经有一段时间没查了。。我真的不记得作者了。不管怎么说,这都是他的功劳:p

为蚂蚁干杯

<!--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>


可能行不通。我希望读取这些文件的任何代码都会使用
ClassLoader.getResource()
调用,该调用在类路径的根中查找。或者(更可能)显式地检查类路径中的文件。是的,如果不更改加载它的代码,只移动该位置中的文件是不起作用的。我想知道这是否是一种更好的组织信息的方法,因为它将信息保存在单独的包(又称名称空间)中。如果想法好的话,我想向SpringSrouce提交一份增强请求。您可能想将26+的问题标记为答案@Xan.lol。我才意识到这是我最高估的答案。。不打勾:p@chzbrgla谢谢你的贡献,帮助其他人不受那么多的痛苦:)这对我来说非常有效。