我正在尝试使用NetBeans 8.2、Maven 3.3.9和声明性服务开发一个Karaf4.1.0应用程序。非常简单的服务可以工作,但是一旦我试图做一些模糊有用的事情,我就会得到可怕的osgi.component缺少的需求错误。
以下是我遇到的问题:
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]
这个问题建议安装scr
feature:install scr因此,我尝试将<feature>scr</feature添加到karat-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大会的有效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>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>整个周末我都在谷歌搜索这个问题:在我看来,互联网上几乎没有任何关于在Karaf中使用声明性服务的文档。
有人能给我一些如何解决问题的建议吗?
史蒂夫
发布于 2017-03-28 23:49:50
不过,我终于摆脱了这个错误--老实说--我不知道我做了什么来弥补它。最后的编辑是从上面列出的特性文件中删除一些在我报告初始问题时根本不存在的内容(我添加了一个<repository />和一个<feature />引用,试图强制安装HttpService.)。
我目前对一个更美好的世界的看法(即我不会在这样的问题上浪费4天)包括:
我认为Karaf和DS都是很酷的工作方式。我希望事情能简单些。
发布于 2017-03-28 06:54:32
您正在尝试获取HTTP服务上的引用,但没有说明是否安装了该功能。
另外,根据使用@Reference的OSGi版本,属性可能无法工作,因此可能需要使用getter/setter (bind/unbind)方法。
请参阅http://blog.vogella.com/2016/06/21/getting-started-with-osgi-declarative-services/第7章. DS注释(感谢Lars Vogel提供这个伟大的教程)。
当开始使用在途时,OSGi项目也是一个很好的地方。
https://stackoverflow.com/questions/43048550
复制相似问题