2016年1月22日 星期五

使用maven-shade 打包apache cxf

使用maven-shade 打包apache cxf



當發生下述exception時,可參考上述文章
Exception in thread "main" org.apache.cxf.service.factory.ServiceConstructionException: Could not resolve a binding for null

使用maven-shade-plugin 打包 采用apache cxf的 jax-rs  可運行jar
必須在pom.xml 的plugin 里添加cxf-buildtools dependency,同时要加入于cxf相關的“transformer”

<plugin>  
    <groupId>org.apache.maven.plugins</groupId>  
    <artifactId>maven-shade-plugin</artifactId>  
<version>2.4.3</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>  


沒有留言:

張貼留言