欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

使用maven-shade 打包apache cxf 为可运行包 出现异常Caused by: org.apache.cxf.BusException:

程序员文章站 2022-07-13 10:39:35
...

 

使用maven-shade-plugin 打包 采用apache cxf的 jax-rs  可运行jar,runtime时 出现异常“

Caused by: org.apache.cxf.BusException: No binding factory for namespace http://xxxxx”,网上找了资料,终于发现原因:必须在pom.xml 的plugin 里添加cxf-buildtools 依赖包,同时要加入于cxf相关的“transformer”如下:

 

 

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
        <version>1.4</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <transformers>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>## you name class name ##</mainClass>
                            </transformer>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>META-INF/spring.handlers</resource>
                            </transformer>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>META-INF/spring.schemas</resource>
                            </transformer>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>META-INF/services/com.sun.tools.xjc.Plugin</resource>
                            </transformer>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>META-INF/cxf/cxf.extension</resource>
                            </transformer>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.XmlAppendingTransformer">
                                <resource>META-INF/extensions.xml</resource>
                            </transformer>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.XmlAppendingTransformer">
                                <resource>META-INF/cxf/extensions.xml</resource>
                            </transformer>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                                <resource>META-INF/cxf/bus-extensions.txt</resource>
                            </transformer>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.XmlAppendingTransformer">
                                <resource>META-INF/cxf/bus-extensions.xml</resource>
                            </transformer>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.XmlAppendingTransformer">
                                <resource>META-INF/wsdl.plugin.xml</resource>
                            </transformer>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.XmlAppendingTransformer">
                                <resource>META-INF/tools.service.validator.xml</resource>
                            </transformer>
                            <transformer implementation="org.apache.cxf.maven.PluginTransformer">
                                <resource>META-INF/tools-plugin.xml</resource>
                            </transformer>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.XmlAppendingTransformer">
                                <resource>META-INF/cxf/java2wsbeans.xml</resource>
                            </transformer>
                            <transformer implementation="org.apache.cxf.maven.CXFAllTransformer" />
                        </transformers>
                        <shadedArtifactAttached>true</shadedArtifactAttached>
                        <shadedClassifierName>executable</shadedClassifierName>
                    </configuration>
                </execution>
            </executions>
            <dependencies>
                <dependency>
                    <groupId>org.apache.cxf</groupId>
                    <artifactId>cxf-buildtools</artifactId>
                    <version>2.2.12</version>
                    <type>jar</type>
                    <scope>compile</scope>
                </dependency>
            </dependencies>
        </plugin>

 

 

再次运行 mvn: clean install 待更新下载相关的cxf-buildtools jar 完毕后~即可 双击运行 打包好的jar,成功调用.....

 

原文出处:

http://*.com/questions/6831954/how-to-package-an-apache-cxf-application-into-a-monolithic-jar-with-the-maven-s