2015-07-10 70 views
0

我有以下服務類:OSGi的DS:不生成的XML文件

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

+0

@Sean Bright謝謝你的時間。我編輯了這篇文章。 –

+0

@Sean Bright你是什麼意思?如果你可以編譯它,你能提供所有的文件嗎? –

+0

@Sean Bright說'捆' –

回答

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

+0

謝謝。它做了詭計。一如既往......一小段代碼。你能解釋什麼是藍圖?我無法理解如何將這個詞翻譯成我的母語。 –

+0

Blueprint是OSGi的另一個依賴注入框架。它源於春天的語法,與它非常相似。你可以在我的其他教程中找到它的一些例子。 –

+0

你能說 - 什麼是正確的方法來添加屬性到@Component?當我做@Component(immediate = false,properties = {「name = stub」})'或'@Component(immediate = false,properties = {「stub」})''我得到felix xml條目解析器異常。 –