我已经解决了,这里是详细信息:
首先,如果您使用内置程序集描述符 jar-with-dependencies,则无法指定文件包含或排除。
程序集插件文档给出了示例jar-with-dependencies descriptor here。
我将该描述符复制并粘贴到我的项目目录中名为 exec-jar.xml 的文件中。然后在 pom 中,我更改了程序集插件以引用该描述符。摘录如下:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-3</version>
<configuration>
<descriptors>
<descriptor>exec-jar.xml</descriptor>
</descriptors>
<archive>
<manifest>
<mainClass>com.package.MyMainClass</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
那位描述符将程序集绑定到生命周期的包阶段,并引用 exec-jar.xml 描述符。执行该包确认 jar 的构建与使用预定义描述符一样。
那么接下来就是修改 exec-jar.xml 以排除与 Spring 文件冲突的 CXF 文件。这是我的程序集描述符,它实现了这一点:
<assembly>
<id>jar-with-dependencies</id>
<formats>
<format>jar</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<unpack>true</unpack>
<unpackOptions>
<excludes>
<exclude>cxf*/META-INF/spring.handlers</exclude>
<exclude>cxf*/META-INF/spring.schemas</exclude>
</excludes>
</unpackOptions>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>${project.build.outputDirectory}</directory>
</fileSet>
</fileSets>
</assembly>
现在问题来了。如果您使用当前发布的程序集插件 2.1 版执行此操作,它将在标记上失败,并显示为“意外”。该标签在插件的未发布版本 2.2 中受支持。请注意,在我上面的 pom 文件摘录中,我指定了 maven-assembly-plugin 版本 2.2-beta-3,这是撰写本文时的最新版本。
这成功构建了一个可执行 jar,Spring 拥有初始化我的应用所需的所有处理程序和架构。