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

Mar*_*sen 5 java osgi provisioning maven 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>
Run Code Online (Sandbox Code Playgroud)

我的模块的依赖项:

            <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>
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,我尝试将功能工件定义为编译范围的依赖项,以及公共语言.其他所有内容都按规定提供.

            <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>
Run Code Online (Sandbox Code Playgroud)

在生成的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>
Run Code Online (Sandbox Code Playgroud)

我想最终得到这个:

<?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>
Run Code Online (Sandbox Code Playgroud)

轻微更新:当我添加<aggregateFeatures>true</aggregateFeatures>到插件配置时,整个cxf功能被解压缩到我的features.xml文件中,但是诸如"cxf"之类的功能依赖性仍未出现在生成的功能中.

Jor*_*nez 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>
Run Code Online (Sandbox Code Playgroud)

我也用: <aggregateFeatures>true</aggregateFeatures>

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