使用cxf jar包装camel项目

时间:2012-07-26 17:39:42

标签: maven plugins apache-camel cxf maven-shade-plugin

我刚刚开始研究Camel,并从一些开箱即用的例子开始。使用mvn camel:run时效果很好。我也试图将其打包为一个超级jar,并能够从命令行执行它。

我正在使用Maven shade插件来构建jar。当我尝试执行它时,我收到此错误:

Caused by: org.apache.cxf.BusException: No DestinationFactory was found for the namespace http://cxf.apache.org/transports/http.
    at org.apache.cxf.transport.DestinationFactoryManagerImpl.getDestinationFactory(DestinationFactoryManagerImpl.java:126)
    at org.apache.cxf.endpoint.ServerImpl.initDestination(ServerImpl.java:88)
    at org.apache.cxf.endpoint.ServerImpl.<init>(ServerImpl.java:72)
    at org.apache.cxf.jaxrs.JAXRSServerFactoryBean.create(JAXRSServerFactoryBean.java:149)

我和其他一些人有这些依赖关系:

    <properties>
      <camel.version>2.8.0-fuse-04-01</camel.version>
      <cxf.version>2.4.3-fuse-02-02</cxf.version>
    </properties>


    <dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-cxf</artifactId>
        <version>${camel.version}</version>
    </dependency>

    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-transports-http-jetty</artifactId>
        <version>${cxf.version}</version>
    </dependency>

以下是在maven shade插件中定义变换器的方法:

    <transformers>
      <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
       <mainClass>org.apache.camel.spring.Main</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>
  </transformers>

我不知道我错过了什么。有人可以帮我解决这个问题吗?请让我知道任何其他方法。

2 个答案:

答案 0 :(得分:2)

您创建的jar中可能没有cxf.xml。

它应位于META-INF/cxf/cxf.xml

Shade可能需要更完整的配置(请参阅instance的此问题)

<configuration>
  <transformers>
    ...
    <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>
  </transformers>
</configuration>

答案 1 :(得分:1)

我有同样的问题。我通过为bus-extensions.txt添加org.apache.maven.plugins.shade.resource.AppendingTransformer解决了这个问题。

这对我有用:

            <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.1</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <shadedArtifactId>${ivyExecutable}</shadedArtifactId>
                        <finalName>${ivyExecutable}</finalName>
                        <createDependencyReducedPom>false</createDependencyReducedPom>
                        <shadedArtifactAttached>true</shadedArtifactAttached>
                        <shadedClassifierName>exec</shadedClassifierName>
                        <artifactSet>
                            <includes>
                                <include>*:*</include>
                            </includes>
                        </artifactSet>

                        <filters>
                            <filter>
                                <artifact>*:*</artifact>
                                <excludes>
                                    <exclude>META-INF/*.SF</exclude>
                                    <exclude>META-INF/*.DSA</exclude>
                                    <exclude>META-INF/*.RSA</exclude>
                                </excludes>
                            </filter>
                        </filters>
                        <transformers>
                            <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.ServicesResourceTransformer"/>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>${mainClass}</mainClass>
                            </transformer>
                        </transformers>
                    </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>