【问题标题】:Include runtime dependencies in karaf:features-generate-descriptor在 karaf:features-generate-descriptor 中包含运行时依赖项
【发布时间】:2023-04-03 13:30:01
【问题描述】:

我有一个 OSGi 项目,其中包含带有编译范围的 sesame-runtime-osgi 依赖项。

<dependency>
    <groupId>org.openrdf.sesame</groupId>
    <artifactId>sesame-runtime-osgi</artifactId>
    <version>${sesame.version}</version>
    <exclusions>
        <exclusion>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
        </exclusion>
    </exclusions>
</dependency>

sesame-runtime-osgi 工件包括几个运行时依赖项。例如:

+- org.openrdf.sesame:sesame-runtime-osgi:jar:2.7.13:compile
|  +- org.openrdf.sesame:sesame-http-client:jar:2.7.13:compile
|  |  +- org.openrdf.sesame:sesame-http-protocol:jar:2.7.13:compile
|  |  |  \- org.openrdf.sesame:sesame-rio-ntriples:jar:2.7.6:compile
|  |  |     \- commons-io:commons-io:jar:2.1:compile
|  |  +- org.openrdf.sesame:sesame-query:jar:2.7.13:compile
.
.
.
|  |  \- commons-codec:commons-codec:jar:1.4:runtime
|  \- org.openrdf.sesame:sesame-http-server-spring:jar:2.7.13:compile
|     +- org.openrdf.sesame:sesame-runtime:jar:2.7.6:compile
|     |  +- org.openrdf.sesame:sesame-repository-manager:jar:2.7.13:compile
.
.
.
|     |  +- org.openrdf.sesame:sesame-queryresultio-sparqljson:jar:2.7.13:runtime
|     |  |  \- com.fasterxml.jackson.core:jackson-core:jar:2.2.2:runtime
|     |  +- org.openrdf.sesame:sesame-queryresultio-text:jar:2.7.13:runtime
|     |  |  \- net.sf.opencsv:opencsv:jar:2.0:runtime
.
.
.
|     \- cglib:cglib:jar:2.2:compile
|        \- asm:asm:jar:3.1:compile

您会注意到“net.sf.opencsv:opencsv:jar:2.0”是一个运行时依赖项,因此它不包含在由 karaf-maven-plugin 生成的 feature.xml 中。不幸的是,运行时所需的包包含在 sesame-runtime-osgi Manifest 的“Import-Packages”指令中:

Import-Package: au.com.bytecode.opencsv

所以除非我自己手动包装和部署运行时依赖项,否则 Karaf 无法部署该功能。显然我不想这样做。

有没有办法可以在 feature.xml 生成中包含运行时范围的依赖项?

谢谢

【问题讨论】:

  • 因为您没有说您使用的是哪个版本的 Karaf maven 插件,您是否 a) 尝试使用 3.0.2,b) 最新快照和 c) 通常最好在karaf 的邮件列表。
  • 对不起,我已经用 3.0.2 和 4.0.0.M1 试过了。 maven-shade-plugin 也会发生类似的情况,但它是通过使用 ServicesResourceTransformer 修复的。我刚刚向用户列表发送了一条消息。感谢您的提示!

标签: maven osgi apache-karaf sesame karaf


【解决方案1】:

如果您使用标准 Karaf mojo 生成 features.xml,那么您可以在 src/main/features/features.xml 中创建功能模板文件 您在该模板中放入的任何内容都将出现在您最终生成的 features.xml 中 因此,如果绝对必要,您可以在模板中对运行时依赖项进行硬编码。

您可以在 pom.xml 中手动指定每个传递依赖项。这大概也可以吗?

【讨论】:

    【解决方案2】:

    只是为了跟进理查德的回答,模板文件应该位于

    src/main/feature/feature.xml
    

    不是

    src/main/features/features.xml
    

    在 feature.xml 模板文件中,您可以包含依赖包和将与生成的功能合并的功能。例如。

    <?xml version="1.0" encoding="UTF-8"?>
    <features name="${project.artifactId}-${project.version}">
      <feature name="${project.artifactId}" description="${project.name}" version="${project.version}">
        <bundle>mvn:net.sf.opencsv/opencsv/2.0</bundle>
      </feature>
    </features>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-19
      • 2011-11-07
      • 1970-01-01
      • 2012-03-15
      • 1970-01-01
      • 1970-01-01
      • 2017-03-05
      • 1970-01-01
      相关资源
      最近更新 更多