我正在尝试使用 NetBeans 8.2、Maven 3.3.9 和声明式服务开发一个 Karaf 4.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
's <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 中使用声明式服务的文档。
谁能给我一些关于如何解决我的问题的提示?
史蒂夫