我有一个基于Maven的Spring-WS客户端项目,我想打包为一个jar。在eclipse中,一切运行正常。当我尝试将它打包为一个可执行的jar时,我得到了ClassNotFound异常,因为Spring jar没有包含在我的应用程序jar中。如何用maven创建基于spring的可执行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>
我的问题是,在包装过程中,我多次对Spring的依赖有不同的META-INF/spring.schemas文件相互覆盖。因此,我的最终jar有一个不完整的spring.schemas文件。因为spring.schemas文件是不完整的(Spring-WS的jar已经覆盖了Spring-core的spring.schemas文件),所以当我尝试运行我的可执行jar时,出现Spring错误消息,说明文件找不到。
我的可执行的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
代替弹簧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
我难倒。我不确定是否/如何将所有内容打包为单个可执行文件。我不知道这是否是阴影插件配置问题,或者我是否尝试做不可能的事情。我不得不手动创建自己的spring.schemas文件(其他连接)。
我可能已经跳了一下枪。在挖阴影插件的更多信息,我注意到我以前错过的AppendingTransformer。但是,我担心如何知道哪些其他文件存在相同的问题?我发现/抓住了这个特殊的春季问题。我不知道任何其他库可能会做类似的事情...
任何意见,将不胜感激。
伟大的工程替代的方法是春季罐子放入单独的lib文件夹,并添加此'lib'夹入清单类路径 - 见安德烈Aronsen的回答http://stackoverflow.com/a/4323501/241986 –