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

标签 spring maven-assembly-plugin meta-inf

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

正如其他人在 forum.springsource.org thread (message #7/8) 上正确发现的那样出现问题是因为存在于不同 jar 中的文件 META-INF/spring.handlersMETA-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.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 中时不会发生冲突。你怎么看?

最佳答案

我设法使用着色器插件而不是(错误的)汇编器插件来消除错误:

        <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

干杯

关于spring - 避免在单个 jar 中合并多个 spring 依赖项时覆盖 spring.handlers/spring.schemas 的想法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5586515/

相关文章:

java - 使用 Redis 创建名称为 'enableRedisKeyspaceNotificationsInitializer' 的 bean 时出错

Maven 程序集插件不包括 .gitignore

android-studio - 发现多个文件具有独立于操作系统的路径 'META-INF/proguard/coroutines.pro'

java - *.jar/META-INF/*.* 中有哪些文件?

java - 使用@ControllerAdvice 测试@RestController

使用 Atomikos JTA 事务管理器时,Spring 单元测试不会回滚

运行 jar 时找不到 jar 中的 Java 属性文件

java - 使用Maven程序集插件设置特定文件的Linux文件权限

android - 需要修改系统应用程序 : original AndroidManifest. xml,但为什么呢?

java - 插入批量更新没有错误,但受影响的行数为-2