相关疑难解决方法(0)

如何用maven创建基于spring的可执行jar?

我有一个基于Maven的Spring-WS客户端项目,我想打包成一个jar.在eclipse中,一切都运行正常.当我尝试将其打包为可执行jar时,我得到ClassNotFound异常,因为Spring jar没有包含在我的应用程序jar中.

所以我添加了maven-shade-plugin来包含我的应用程序jar中的所有依赖项.当我查看我的app 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>
Run Code Online (Sandbox Code Playgroud)

我的问题是在打包过程中,我的多个spring依赖项有不同的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
Run Code Online (Sandbox Code Playgroud)

而不是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
Run Code Online (Sandbox Code Playgroud)

我很难过.我不确定是否/如何将所有内容打包为单个可执行jar.我不知道这是一个阴影插件配置问题,还是我试图做一些不可能的事情.我不得不手动创建自己的spring.schemas文件(其他的串联)似乎是不正确的.

我可能有点跳了一下枪.在挖掘插件的更多信息时,我注意到我之前错过的AppendingTransformer.但是,我关心的是如何知道哪些其他文件有同样的问题?我发现/抓住了这个特殊的Spring问题.我不知道任何其他可能正在做类似事情的库......

任何建议,将不胜感激.

java spring spring-ws maven maven-shade-plugin

28
推荐指数
3
解决办法
4万
查看次数

标签 统计

java ×1

maven ×1

maven-shade-plugin ×1

spring ×1

spring-ws ×1