如何使用maven创建基于弹簧的可执行罐?
我有一个基于Maven的Spring-WS客户端项目,我想将其打包为单个jar。在日食中,一切都运行正常。当我尝试将其打包为可执行jar时,我得到了ClassNotFound异常,因为Spring jar不包括在我的应用程序jar中。
因此,我添加了 maven-shade-plugin,以在我的应用程序 jar 中包含我的所有依赖项。当我查看我的应用程序jar时,我看到来自包含的所有依赖项的所有类文件(所有库jar都爆炸了)。
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.cws.cs.Client</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
我的问题是,在打包过程中,我的多个弹簧依赖项具有不同的 META-INF/spring.schemas 文件,这些文件相互覆盖。因此,我的最终jar有一个不完整的spring.schemas文件。
因此,当我尝试运行可执行jar时,我收到Spring错误消息,指出由于spring.schemas文件不完整而找不到文件(Spring-WS的jar已覆盖Spring-core的spring.schemas文件)。
我的可执行jar的META-INF/spring.schemas:
http\://www.springframework.org/schema/web-services/web-services-1.5.xsd=/org/springframework/ws/config/web-services-1.5.xsd
http\://www.springframework.org/schema/web-services/web-services-2.0.xsd=/org/springframework/ws/config/web-services-2.0.xsd
http\://www.springframework.org/schema/web-services/web-services.xsd=/org/springframework/ws/config/web-services-2.0.xsd
而不是Spring-beans.jar META-INF/spring.schemas:
http\://www.springframework.org/schema/beans/spring-beans-2.0.xsd=org/springframework/beans/factory/xml/spring-beans-2.0.xsd
http\://www.springframework.org/schema/beans/spring-beans-2.5.xsd=org/springframework/beans/factory/xml/spring-beans-2.5.xsd
http\://www.springframework.org/schema/beans/spring-beans-3.0.xsd=org/springframework/beans/factory/xml/spring-beans-3.0.xsd
http\://www.springframework.org/schema/beans/spring-beans-3.1.xsd=org/springframework/beans/factory/xml/spring-beans-3.1.xsd
http\://www.springframework.org/schema/beans/spring-beans.xsd=org/springframework/beans/factory/xml/spring-beans-3.1.xsd
http\://www.springframework.org/schema/tool/spring-tool-2.0.xsd=org/springframework/beans/factory/xml/spring-tool-2.0.xsd
http\://www.springframework.org/schema/tool/spring-tool-2.5.xsd=org/springframework/beans/factory/xml/spring-tool-2.5.xsd
http\://www.springframework.org/schema/tool/spring-tool-3.0.xsd=org/springframework/beans/factory/xml/spring-tool-3.0.xsd
http\://www.springframework.org/schema/tool/spring-tool-3.1.xsd=org/springframework/beans/factory/xml/spring-tool-3.1.xsd
http\://www.springframework.org/schema/tool/spring-tool.xsd=org/springframework/beans/factory/xml/spring-tool-3.1.xsd
http\://www.springframework.org/schema/util/spring-util-2.0.xsd=org/springframework/beans/factory/xml/spring-util-2.0.xsd
http\://www.springframework.org/schema/util/spring-util-2.5.xsd=org/springframework/beans/factory/xml/spring-util-2.5.xsd
http\://www.springframework.org/schema/util/spring-util-3.0.xsd=org/springframework/beans/factory/xml/spring-util-3.0.xsd
http\://www.springframework.org/schema/util/spring-util-3.1.xsd=org/springframework/beans/factory/xml/spring-util-3.1.xsd
http\://www.springframework.org/schema/util/spring-util.xsd=org/springframework/beans/factory/xml/spring-util-3.1.xsd
我很困惑。我不确定我是否/如何将所有内容打包为单个可执行jar。我不知道这是否是阴影插件配置问题,或者我是否试图做一些不可能的事情。我必须手动创建自己的spring.schemas文件(其他文件的串联)似乎是不正确的。
我可能有点跳枪了。在挖掘有关shade插件的更多信息时,我注意到我以前错过的AddingTransformer。但是,我担心的是如何知道哪些其他文件有同样的问题?我发现/抓住了这个特殊的春季问题。我不知道任何其他可能正在做类似事情的库......
任何建议将不胜感激。