【问题标题】:OSGi DS: xml file is not generatedOSGi DS:未生成 xml 文件
【发布时间】:2015-09-29 03:54:42
【问题描述】:

我有以下服务等级:

@Component(immediate = true)
@Service
public class Myclass implements MyInterface
{
    @Override
    public String doIt()
    {
        return "This is default bean";
    }
}

在 pom 文件中我有:

<dependency>
    <groupId>org.apache.felix</groupId>
    <artifactId>org.apache.felix.scr.annotations</artifactId>
    <version>1.9.6</version>
    <scope>provided</scope>
</dependency>
...
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <version>2.4.0</version>
            <extensions>true</extensions>
            <configuration>
                <instructions>
                    <_include>
                        -target/classes/META-INF/beans.bnd
                    </_include>
                    <Export-Package></Export-Package>
                    <Private-Package>com.company.temp.*</Private-Package>
                </instructions>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-scr-plugin</artifactId>
            <version>1.21.0</version>
            <executions>
                <execution>
                    <id>generate-scr-scrdescriptor</id>
                    <goals>
                        <goal>scr</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        ...
    <plugins>
</build>

问题是没有生成 DS 的 xml 文件。此外,清单文件中没有 Service-Component 行。我的错误在哪里(PS java8)?

【问题讨论】:

  • @Sean Bright 感谢您抽出宝贵时间。我已经编辑了帖子。
  • @Sean Bright 你是什么意思?如果你可以编译,你能提供所有的文件吗?
  • @Sean Bright 它说bundle

标签: java maven osgi apache-felix


【解决方案1】:

如果您打算使用标准 DS 注释(而不是 felix 注释)。然后只需使用下面的配置。

<plugin>
    <groupId>org.apache.felix</groupId>
    <artifactId>maven-bundle-plugin</artifactId>
    <version>2.5.4</version>
    <extensions>true</extensions>
    <configuration>
        <instructions>
            <_dsannotations>*</_dsannotations>
        </instructions>
    </configuration>
</plugin>

如果您需要完整的示例,我也有一个DS tutorial

【讨论】:

  • 谢谢。它成功了。一如既往...一小行代码。你能解释一下什么是蓝图吗?我不明白如何将这个词翻译成我的母语。
  • Blueprint 是 OSGi 的另一个依赖注入框架。它源自 spring 语法,与它非常相似。你可以在我的其他教程中找到一些例子。
  • 您能说一下 - 向@Component 添加属性的正确方法是什么?当我执行 @Component(immediate = false,properties = {"name=stub"})@Component(immediate = false,properties = {"stub"}) 时,我得到 felix xml 条目解析器异常。
  • 我的教程中有一个例子:property="osgi.remote.interfaces:String=*"
  • 谢谢。我试过 @Component(immediate = false,properties = {"name:String=stub"}) 但有同样的问题。
猜你喜欢
  • 1970-01-01
  • 2016-08-26
  • 2023-04-02
  • 1970-01-01
  • 1970-01-01
  • 2013-12-27
  • 1970-01-01
  • 1970-01-01
  • 2013-04-10
相关资源
最近更新 更多