2017-03-27 185 views
0

我正在嘗試開發一個使用NetBeans 8.2,Maven 3.3.9和聲明式服務的Karaf 4.1.0應用程序。真正簡單的服務工作,但只要我嘗試做一些模糊的事情,我就會得到可怕的osgi.component缺少的需求錯誤。在Karaf中使用聲明式服務4.1.0

以下說明了這類問題我有:

package net.winnall.enocean.bridge.sass.impl; 

import org.osgi.service.component.annotations.Activate; 
import org.osgi.service.component.annotations.Component; 
import org.osgi.service.component.annotations.Deactivate; 
import org.osgi.service.component.annotations.Reference; 
import org.slf4j.Logger; 
import org.slf4j.LoggerFactory; 
import net.winnall.enocean.bridge.sass.SASS; 
import org.osgi.service.http.HttpService; 

@Component(
     service = SASS.class 
) 
public class SASSImpl implements SASS { 

    @Reference 
    HttpService httpService; 

    @Activate 
    protected void activate() { 
    } 

    @Deactivate 
    } 
} 

如果我註釋掉@Reference組件被加載到產生Karaf組件沒有任何問題。但是,隨着組件站在這裏(用@Reference)我收到以下錯誤:

Failed to execute goal org.apache.karaf.tooling:karaf-maven-plugin:4.1.0:assembly (default-assembly) on project EnOceanBridgeAdmin: Unable to build assembly: Unable to resolve root: missing requirement [root] osgi.identity; osgi.identity=EnOceanBridgeSASSFeature; type=karaf.feature; version=0.99.99; filter:="(&(osgi.identity=EnOceanBridgeSASSFeature)(type=karaf.feature)(version>=0.99.99))" [caused by: Unable to resolve EnOceanBridgeSASSFeature/0.99.99: missing requirement [EnOceanBridgeSASSFeature/0.99.99] osgi.identity; osgi.identity=EnOceanBridgeSASS.Impl; type=osgi.bundle; version="[0.99.99,0.99.99]"; resolution:=mandatory [caused by: Unable to resolve EnOceanBridgeSASS.Impl/0.99.99: missing requirement [EnOceanBridgeSASS.Impl/0.99.99] osgi.extender; filter:="(&(osgi.extender=osgi.component)(version>=1.3.0)(!(version>=2.0.0)))"]] -> [Help 1]

This question建議安裝scr

feature:install scr 

所以我嘗試添加<feature>scr</featurekarat-maven-plugin<bootFeatures>,但沒什麼區別。

下面是從有效POM此成分的提取物:

<dependencyManagement> 
    <dependencies> 
     <dependency> 
     <groupId>org.apache.felix</groupId> 
     <artifactId>org.apache.felix.configadmin</artifactId> 
     <version>1.8.14</version> 
     </dependency> 

     <dependency> 
     <groupId>org.apache.felix</groupId> 
     <artifactId>org.apache.felix.scr.ds-annotations</artifactId> 
     <version>1.2.8</version> 
     </dependency> 

     <dependency> 
     <groupId>org.ops4j.pax.logging</groupId> 
     <artifactId>pax-logging-service</artifactId> 
     <version>1.9.1</version> 
     </dependency> 

     <dependency> 
     <groupId>org.ops4j.pax.logging</groupId> 
     <artifactId>pax-logging-api</artifactId> 
     <version>1.9.1</version> 
     </dependency> 

     <dependency> 
     <groupId>org.ops4j.pax.logging</groupId> 
     <artifactId>pax-logging-log4j2</artifactId> 
     <version>1.9.1</version> 
     </dependency> 
    </dependencies> 
    </dependencyManagement> 

    <dependencies> 
    <dependency> 
     <groupId>org.apache.karaf.features</groupId> 
     <artifactId>framework</artifactId> 
     <version>4.1.0</version> 
     <type>kar</type> 
     <scope>compile</scope> 
    </dependency> 

    <dependency> 
     <groupId>org.apache.karaf.features</groupId> 
     <artifactId>standard</artifactId> 
     <version>4.1.0</version> 
     <type>xml</type> 
     <classifier>features</classifier> 
     <scope>runtime</scope> 
    </dependency> 
    </dependencies> 

    <build> 
    <pluginManagement> 
     <plugins> 
     <plugin> 
      <groupId>org.apache.karaf.tooling</groupId> 
      <artifactId>karaf-maven-plugin</artifactId> 
      <version>4.1.0</version> 
      <extensions>true</extensions> 
     </plugin> 
     </plugins> 
    </pluginManagement> 

    <plugins> 
     <plugin> 
     <groupId>org.apache.karaf.tooling</groupId> 
     <artifactId>karaf-maven-plugin</artifactId> 
     <version>4.1.0</version> 
     <extensions>true</extensions> 
     <configuration> 
      <installedFeatures></installedFeatures> 
      <startupFeatures></startupFeatures> 
      <bootFeatures> 
      <feature>minimal</feature> 
      <feature>scr</feature> 
      </bootFeatures> 
      <javase>1.8</javase> 
     </configuration> 
     </plugin> 

我用讓他們知道到Karaf裝配的特點是:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> 
<features xmlns="http://karaf.apache.org/xmlns/features/v1.4.0" name="EnOceanBridgeSASS.Impl"> 
    <feature name="EnOceanBridgeSASS.Impl" description="EnOceanBridge SASS Impl" version="0.99.99"> 
     <details>Karaf :: Declarative Services :: Service :: EnOceanBridge SASS Implementation</details> 
     <bundle start-level="80">mvn:net.winnall.enocean.service.api/EnOceanBridgeSASS.API/0.99.99</bundle> 
     <bundle start-level="80">mvn:org.apache.felix/org.apache.felix.configadmin/1.8.14</bundle> 
     <bundle start-level="80">mvn:org.ops4j.pax.logging/pax-logging-api/1.9.1</bundle> 
     <bundle start-level="80">mvn:org.ops4j.pax.logging/pax-logging-service/1.9.1</bundle> 
    </feature> 
</features> 

而且Karaf大會有效聚甲醛包含此:

<dependencyManagement> 
    <dependencies> 
     <dependency> 
     <groupId>org.apache.felix</groupId> 
     <artifactId>org.apache.felix.configadmin</artifactId> 
     <version>1.8.14</version> 
     </dependency> 

     <dependency> 
     <groupId>org.apache.felix</groupId> 
     <artifactId>org.apache.felix.scr.ds-annotations</artifactId> 
     <version>1.2.8</version> 
     </dependency> 

     <dependency> 
     <groupId>org.ops4j.pax.logging</groupId> 
     <artifactId>pax-logging-service</artifactId> 
     <version>1.9.1</version> 
     </dependency> 

     <dependency> 
     <groupId>org.ops4j.pax.logging</groupId> 
     <artifactId>pax-logging-api</artifactId> 
     <version>1.9.1</version> 
     </dependency> 

     <dependency> 
     <groupId>org.ops4j.pax.logging</groupId> 
     <artifactId>pax-logging-log4j2</artifactId> 
     <version>1.9.1</version> 
     </dependency> 
    </dependencies> 
    </dependencyManagement> 

    <dependencies> 
    <dependency> 
     <groupId>net.winnall.enocean.feature</groupId> 
     <artifactId>EnOceanBridgeSettingsFeature</artifactId> 
     <version>0.99.99</version> 
     <type>xml</type> 
     <classifier>features</classifier> 
     <scope>compile</scope> 
    </dependency> 

    <dependency> 
     <groupId>net.winnall.enocean.feature</groupId> 
     <artifactId>EnOceanBridgeSASSFeature</artifactId> 
     <version>0.99.99</version> 
     <type>xml</type> 
     <classifier>features</classifier> 
     <scope>compile</scope> 
    </dependency> 

    <dependency> 
     <groupId>net.winnall.enocean.feature</groupId> 
     <artifactId>EnOceanBridgePersistenceFeature</artifactId> 
     <version>0.99.99</version> 
     <type>xml</type> 
     <classifier>features</classifier> 
     <scope>compile</scope> 
    </dependency> 

    <dependency> 
     <groupId>org.apache.karaf.features</groupId> 
     <artifactId>framework</artifactId> 
     <version>4.1.0</version> 
     <type>kar</type> 
     <scope>compile</scope> 
    </dependency> 

    <dependency> 
     <groupId>org.apache.karaf.features</groupId> 
     <artifactId>standard</artifactId> 
     <version>4.1.0</version> 
     <type>xml</type> 
     <classifier>features</classifier> 
     <scope>runtime</scope> 
    </dependency> 
    </dependencies> 

    <build> 
    <pluginManagement> 
     <plugins> 
     <plugin> 
      <groupId>org.apache.karaf.tooling</groupId> 
      <artifactId>karaf-maven-plugin</artifactId> 
      <version>4.1.0</version> 
      <extensions>true</extensions> 
     </plugin> 

     <plugin> 
      <artifactId>maven-archetype-plugin</artifactId> 
      <version>3.0.0</version> 
     </plugin> 

     <plugin> 
      <groupId>com.github.ferstl</groupId> 
      <artifactId>depgraph-maven-plugin</artifactId> 
      <version>2.1.0</version> 
     </plugin> 

     <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>exec-maven-plugin</artifactId> 
      <version>1.6.0</version> 
     </plugin> 

     <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>license-maven-plugin</artifactId> 
      <version>1.12</version> 
     </plugin> 

     <plugin> 
      <artifactId>maven-antrun-plugin</artifactId> 
      <version>1.8</version> 
     </plugin> 

     <plugin> 
      <artifactId>maven-assembly-plugin</artifactId> 
      <version>2.2-beta-5</version> 
     </plugin> 

     <plugin> 
      <artifactId>maven-dependency-plugin</artifactId> 
      <version>2.1</version> 
     </plugin> 

     <plugin> 
      <artifactId>maven-release-plugin</artifactId> 
      <version>2.0</version> 
     </plugin> 

     <plugin> 
      <groupId>org.apache.felix</groupId> 
      <artifactId>maven-bundle-plugin</artifactId> 
      <version>3.3.0</version> 
     </plugin> 

     <plugin> 
      <artifactId>maven-resources-plugin</artifactId> 
      <version>3.0.2</version> 
     </plugin> 
     </plugins> 
    </pluginManagement> 

    <plugins> 
     <plugin> 
     <groupId>com.github.ferstl</groupId> 
     <artifactId>depgraph-maven-plugin</artifactId> 
     <version>2.1.0</version> 
     </plugin> 

     <plugin> 
     <artifactId>maven-resources-plugin</artifactId> 
     <version>3.0.2</version> 
     <executions> 
      <execution> 
      <id>default-resources</id> 
      <phase>process-resources</phase> 
      <goals> 
       <goal>resources</goal> 
      </goals> 
      </execution> 
      <execution> 
      <id>process-resources</id> 
      <goals> 
       <goal>resources</goal> 
      </goals> 
      </execution> 
     </executions> 
     </plugin> 

     <plugin> 
     <groupId>org.apache.karaf.tooling</groupId> 
     <artifactId>karaf-maven-plugin</artifactId> 
     <version>4.1.0</version> 
     <extensions>true</extensions> 
     <executions> 
      <execution> 
      <id>default-archive</id> 
      <phase>package</phase> 
      <goals> 
       <goal>archive</goal> 
      </goals> 
      <configuration> 
       <installedFeatures></installedFeatures> 
       <startupFeatures></startupFeatures> 
       <bootFeatures> 
       <feature>minimal</feature> 
       <feature>scr</feature> 
       </bootFeatures> 
       <javase>1.8</javase> 
      </configuration> 
      </execution> 

      <execution> 
      <id>default-assembly</id> 
      <phase>process-resources</phase> 
      <goals> 
       <goal>assembly</goal> 
      </goals> 
      <configuration> 
       <installedFeatures></installedFeatures> 
       <startupFeatures></startupFeatures> 
       <bootFeatures> 
       <feature>minimal</feature> 
       <feature>scr</feature> 
       </bootFeatures> 
       <javase>1.8</javase> 
      </configuration> 
      </execution> 
     </executions> 

     <configuration> 
      <installedFeatures></installedFeatures> 
      <startupFeatures></startupFeatures> 
      <bootFeatures> 
      <feature>standard</feature> 
      <feature>scr</feature> 
      </bootFeatures> 
      <javase>1.8</javase> 
     </configuration> 
     </plugin> 

我花了整個週末googling這個概率lem:在我看來,互聯網上幾乎沒有關於在Karaf中使用聲明式服務的文檔。

任何人都可以給我一些關於如何解決我的問題的提示?

史蒂夫

+0

我厭倦了看到上面的錯誤信息。誰能告訴我這是什麼意思? –

回答

0

儘管我終於擺脫了錯誤 - 說實話 - 我不知道我是如何解決它的。使這件事情起作用的最終編輯是從上面列出的功能文件中刪除一些東西,當我報告最初的問題時(這是一個<repository /><feature />引用,我曾經徒勞地嘗試添加強制安裝HttpService ...)。我現在對更好的可能世界的看法(即在這種問題上我不會失去4天)包括:

  1. OSGi錯誤消息,幫助程序員隔離錯誤;
  2. 一種告訴Google的方式,我真的只對聲明性服務(即基於註解而非原始的BND或XML文件)的最新版本感興趣;
  3. 更清晰的基於註釋的DS文檔沒有插圖說明如何在Eclipse中完成它,因爲我不使用Eclipse並且不想;
  4. 關於如何在Karaf中使用DS的更簡單的文檔;
  5. 一個Karaf IDE(這是什麼卡拉夫啓動是?)。

我覺得Karaf和DS都是很酷的工作方式。我希望它更容易。

+0

剛剛完成:我認爲錯誤發生在我的一個POM中,但我不確定。 –

0

您正試圖獲得對HTTP服務的引用,但如果你已經安裝了該功能,在你沒有說明。

也取決於使用@Reference屬性的OSGi版本可能無法正常工作,您可能需要使用getter/setter(bind/unbind)方法。

http://blog.vogella.com/2016/06/21/getting-started-with-osgi-declarative-services/第7章DS註解 (感謝拉爾斯·沃格爾對這個偉大的教程)。

enroute項目也是一個偉大的地方使用OSGi啓動時。

+0

我一整天都在追求這個提示,但我沒有比周五更進一步。我認爲問題出在我對卡拉夫的理解(或缺乏),而不是DS。我認爲Karaf的全部重點是它爲你提供了像'HttpService'這樣的服務?通過'pax-web'?通過'http'?但是我找不到哪個功能。 –