2

我刚开始研究 Camel,并从一些开箱即用的示例开始。使用 mvn 时效果很好camel:run。我也在尝试将其打包为一个 uber 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>

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

4

2 回答 2

2

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

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

阴影可能需要更完整的配置(例如参见这个问题)

<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>
于 2012-07-27T11:43:17.340 回答
1

我遇到过同样的问题。我通过添加一个org.apache.maven.plugins.shade.resource.AppendingTransformerfor bus-extensions.txt 解决了这个问题。

这对我有用:

            <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>
于 2013-09-25T13:51:22.527 回答