我遇到了这个问题:
我有一个带有spring-boot的项目。它在 eclipse 上完美运行,但我需要生成一个带有依赖项的 jar,所以我将 maven-assembly-plugin 配置添加到 pom.xml 中。
一些 spring 依赖项在 META-INF 中有一个名为 spring.schemas 的文件,我需要将所有 spring.schemas 合并为一个(spring-context、spring-beans 等)
我使用 maven-shade-pluggin 和 AppendingTransformer 尝试了这个解决方案,它完美地合并了所有 spring.schemas ......但是它有一个问题,当我执行 jar 时,它失败了:
java.lang.IllegalStateException: Unable to open nested entry 'lib/spring-boot-starter-batch-1.2.4.RELEASE.jar'.
It has been compressed and nested jar files must be stored without compression.
Please check the mechanism used to create your executable jar file
所以,shade插件压缩jar,spring-boot不喜欢,也没有办法关闭shade压缩。我手动复制了 shade 生成的 shade spring.schemas 并将其放入 maven-assembly-pluggin 生成和未压缩的具有依赖关系的 jar 中。有用。
然后我尝试将生成的 spring.schemas 包含到我的资源文件夹中,但它总是被 spring-context 中的 spring.schemas 覆盖。
我还尝试了其他解决方案,以在程序集中使用描述符 XML 从依赖项 jar 中排除 spring.schemas,但它不起作用:
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
<id>distribution</id>
<formats>
<format>jar</format>
</formats>
<dependencySets>
<dependencySet>
<outputDirectory>/</outputDirectory>
<includes>
<include>org.springframework:spring-context</include>
</includes>
<unpack>true</unpack>
<unpackOptions>
<excludes>
<exclude>**/spring.schemas</exclude>
</excludes>
</unpackOptions>
</dependencySet>
<dependencySet>
<outputDirectory>/</outputDirectory>
<excludes>
<exclude>org.springframework:spring-context</exclude>
</excludes>
<unpack>true</unpack>
</dependencySet>
</dependencySets>
</assembly>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>org.springframework.batch.core.launch.support.CommandLineJobRunner</mainClass>
</manifest>
<compress>false</compress>
</archive>
<descriptors>
<descriptor>src/main/assembly/distribution.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
这是我的依赖项:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-batch</artifactId>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
</dependency>
<!-- MySql 5.5 Connector -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.35</version>
</dependency>
</dependencies>
有任何想法吗?提前致谢