karaf-maven-plugin:将依赖项定义为一项功能

时间:2015-04-15 08:42:32

标签: java maven osgi provisioning apache-karaf

我正在尝试让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>

轻微更新: 当我将<aggregateFeatures>true</aggregateFeatures>添加到插件配置时,整个cxf功能将解压缩到我的features.xml文件中,但功能依赖性如&#34; cxf&#34;仍未出现在生成的特征中。

1 个答案:

答案 0 :(得分:6)

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

<?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>

我还使用:<aggregateFeatures>true</aggregateFeatures>

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