Issue
I'm getting this error when attempting to start a bundle:
org.osgi.framework.BundleException:
Unable to resolve com.example.test [7](R 7.0):
missing requirement [com.example.test [7](R 7.0)] osgi.extender; (&(osgi.extender=osgi.component)(version>=1.3.0)(!(version>=2.0.0)))
Unresolved requirements:
[[com.example.test [7](R 7.0)] osgi.extender; (&(osgi.extender=osgi.component)(version>=1.3.0)(!(version>=2.0.0)))]
My pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>test</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>bundle</packaging>
<dependencies>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>6.0.0</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.component.annotations</artifactId>
<version>1.4.0</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>4.0.0</version>
<extensions>true</extensions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<configuration>
<instructions>
<Export-Package>com.example</Export-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
</project>
Code:
Facade.java:
package com.example;
public interface Facade {}
FacadeLocator.java:
package com.example;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
@Component
public class FacadeLocator {
public static Facade facade;
@Reference
public void setFacade(Facade facade) {
FacadeLocator.facade = facade;
}
}
What am I doing wrong?
Thank you
Solution
Your bundle contains a Declarative Services component -- FacadeLocator
from your code. This means you have a dependency on the "extender" bundle that implements Declarative Services. You need to deploy that bundle alongside your own bundle in order for it to work.
The DS implementation bundle from Apache Felix has the name org.apache.felix.scr
and it can be downloaded from Maven Central.
The error message you saw can be decoded as follows. You have a missing requirement in the osgi.extender
namespace, (the namespace for extenders similar to DS). The specific extender you require is osgi.component
, version 1.3 or above. The maven-bundle-plugin generated this requirement in your bundle's META-INF/MANIFEST.MF because it saw your bundle has a component in it. Whenever a bundle has a requirement, there must be another bundle that provides a matching capability. In this case, that bundle is org.apache.felix.scr
.
Answered By - Neil Bartlett
Answer Checked By - David Marino (JavaFixing Volunteer)