【问题标题】:karaf-maven-plugin: Defining a dependency as a featurekaraf-maven-plugin:将依赖项定义为特性
【发布时间】:2015-06-21 03:18:48
【问题描述】:

我正在尝试让 karaf-maven-plugin 为我的应用程序生成一个功能文件。该应用程序依赖于 cxf 功能,但我似乎无法让插件生成功能 xml 来反映这一点。

我的功能模块截图:

    <dependencies>
        <dependency>
            <groupId>com.test.test</groupId>
            <artifactId>test</artifactId>
        </dependency>
    </dependencies>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.karaf.tooling</groupId>
                    <artifactId>karaf-maven-plugin</artifactId>
                    <version>3.0.3</version>
                    <extensions>true</extensions>
                </plugin>
            </plugins>
        </pluginManagement>
    <plugins>
      <plugin>
        <groupId>org.apache.karaf.tooling</groupId>
        <artifactId>karaf-maven-plugin</artifactId>
          <configuration>
            <startLevel>80</startLevel>
        <includeTransitiveDependency>true</includeTransitiveDependency>
        <aggregateFeatures>false</aggregateFeatures>
          </configuration>
        </plugin>
        </plugins>
    </build>

来自我的模块的依赖项:

            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
                <version>${slf4j.version}</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-log4j12</artifactId>
                <version>${slf4j.version}</version>
                <scope>provided</scope>
            </dependency>

            <dependency>
                <groupId>log4j</groupId>
                <artifactId>log4j</artifactId>
                <version>1.2.17</version>
                <scope>provided</scope>
            </dependency>

            <dependency>
                <groupId>org.osgi</groupId>
                <artifactId>org.osgi.core</artifactId>
                <version>5.0.0</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.osgi</groupId>
                <artifactId>org.osgi.compendium</artifactId>
                <version>5.0.0</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.felix</groupId>
                <artifactId>org.apache.felix.configadmin</artifactId>
                <version>1.8.0</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.mybatis</groupId>
                <artifactId>mybatis</artifactId>
                <version>3.2.8</version>
                <scope>provided</scope>
            </dependency>

            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.12</version>
                <scope>provided</scope>
            </dependency>

            <dependency>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-rt-frontend-jaxrs</artifactId>
                <version>${cxf.version}</version>
                <scope>provided</scope>
            </dependency>
            <!-- use extension providers -->
            <dependency>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-rt-rs-extension-providers</artifactId>
                <version>${cxf.version}</version>
                <scope>provided</scope>
            </dependency>
            <!-- use Jackson -->
            <dependency>
                <groupId>org.codehaus.jackson</groupId>
                <artifactId>jackson-jaxrs</artifactId>
                <version>1.9.13</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.codehaus.jackson</groupId>
                <artifactId>jackson-xc</artifactId>
                <version>1.9.13</version>
                <scope>provided</scope>
            </dependency>

            <dependency>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-rt-transports-http</artifactId>
                <version>${cxf.version}</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-rt-ws-security</artifactId>
                <version>${cxf.version}</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-rt-ws-policy</artifactId>
                <version>${cxf.version}</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-rt-ws-addr</artifactId>
                <version>${cxf.version}</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-rt-frontend-jaxws</artifactId>
                <version>${cxf.version}</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-rt-rs-client</artifactId>
                <version>${cxf.version}</version>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-rt-transports-http-hc</artifactId>
                <version>${cxf.version}</version>
                <scope>provided</scope>
            </dependency>

            <dependency>
                <groupId>org.apache.cxf.karaf</groupId>
                <artifactId>apache-cxf</artifactId>
                <version>${cxf.version}</version>
                <classifier>features</classifier>
                <type>xml</type>
            </dependency>


            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-lang3</artifactId>
                <version>3.3.2</version>
            </dependency>
        </dependencies>

如您所见,我尝试将功能工件定义为编译范围的依赖项,以及 commons lang。其他所有内容均按照提供的范围进行。

            <dependency>
                <groupId>org.apache.cxf.karaf</groupId>
                <artifactId>apache-cxf</artifactId>
                <version>${cxf.version}</version>
                <classifier>features</classifier>
                <type>xml</type>
            </dependency>


            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-lang3</artifactId>
                <version>3.3.2</version>
            </dependency>

在生成的 features.xml 文件中,commons 包已注册,但功能未注册:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.1" name="feature">
    <feature name="feature" version="0.1-SNAPSHOT" description="test-feature">
        <details>test</details>
        <bundle start-level="80">mvn:com.test.test/test/0.1-SNAPSHOT</bundle>
        <bundle start-level="80">mvn:org.apache.commons/commons-lang3/3.3.2</bundle>
    </feature>
</features>

我想这样结束:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.1" name="feature">
    <feature name="feature" version="0.1-SNAPSHOT" description="test-feature">
        <details>test</details>
        <feature version="3.0.2">cxf</feature>
        <bundle start-level="80">mvn:com.test.test/test/0.1-SNAPSHOT</bundle>
        <bundle start-level="80">mvn:org.apache.commons/commons-lang3/3.3.2</bundle>
    </feature>
</features>

轻微更新: 当我将&lt;aggregateFeatures&gt;true&lt;/aggregateFeatures&gt; 添加到插件配置中时,整个 cxf 功能被解压缩到我的 features.xml 文件中,但是像“cxf”这样的功能依赖项仍然没有出现在生成的功能中。

【问题讨论】:

    标签: java maven osgi provisioning apache-karaf


    【解决方案1】:

    恕我直言,这是 karaf-maven-plugin 中的错误或未完成的问题。我曾经也有过一样的问题。 对我来说,我找到的解决方案是在 src/main/feature 下添加一个 feature.xml 模板,其中包含我需要的功能和其他文件(配置文件)。在你的情况下会是这样的:

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <features xmlns="http://karaf.apache.org/xmlns/features/v1.2.1" name="feature">
        <feature name="feature" version="${yourprojectversion}" description="test-feature">
            <feature version="${cxf.version}">cxf</feature>
        </feature>
    </features>
    

    我也用:&lt;aggregateFeatures&gt;true&lt;/aggregateFeatures&gt;

    请注意,在我的功能模板中,我使用了一些自定义 maven 属性来处理 pom.xml 中定义的版本。 最后,您将获得您期望的功能。

    【讨论】:

      【解决方案2】:

      如果要将依赖项作为捆绑包包含在生成的 features.xml 文件中,则需要将依赖项标记为范围“运行时”。

      【讨论】:

        猜你喜欢
        • 2018-02-28
        • 2013-11-16
        • 2019-12-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多