Eclipse OSGI unsatisfied constraint

2.8k views Asked by At

I have a basic OSGI project in Eclipse. When I created a class Activator and imported the BundleActivator, Eclipse changed the MANIFEST.MF adding these lines:

Export-Package: my.package.name;uses:="org.osgi.framework";version="0.0.1.SNAPSHOT"
Import-Package: org.osgi.framework;version="[1.8,2)"

Now Eclipse ("problems view") prompts this error message:

Unsatisfied constraint: 'Import-Package: org.osgi.framework; version="[1.8.0,2.0.0)"'   Plug-in Problem MANIFEST.MF

I have imported the newest Apache Felix runtime and it can be found as a Maven dependency, but that does not solve the problem, when running from within Eclipse.

What do I need to change to solve the dependency? Why does it print versions 1.8.0,2.0.0?

Update

Plugin part of pom.xml:

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

            <configuration>
                <manifestLocation>src/main/resources/META-INF</manifestLocation>
                <rebuildBundle>true</rebuildBundle>
                <instructions>

                    <Bundle-Activator>my.package.name.Activator</Bundle-Activator>
                    <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
                    <Bundle-RequiredExecutionEnvironment>JavaSE-1.7</Bundle-RequiredExecutionEnvironment>

                </instructions>
            </configuration>

            <!-- EXECUTION -->

            <extensions>true</extensions>
            <executions>
                <execution>
                    <id>set_failok</id>
                    <goals>
                        <goal>manifest</goal>
                    </goals>
                    <configuration>
                        <instructions>
                            <_failok>true</_failok>
                        </instructions>
                    </configuration>
                </execution>
            </executions>
        </plugin>

Dependency part of pom.xml (import works well):

<dependency>
 <groupId>org.apache.felix</groupId>
 <artifactId>org.apache.felix.framework</artifactId>                     
 <version>5.0.0</version>
</dependency>
1

There are 1 answers

2
Christian Schneider On BEST ANSWER

The maven bundle plugin looks into the manifests of the bundles you depend on to determine the package versions.

it finds that you use the package org.osgi.framework and that felix framework 5.0.0 exports this package with version 1.8.0. So it creates an import range from this version until excluding the next major version.

So your Manifest looks good. The reason why you can not run from eclipse might be that you use a lower OSGi framework version there that does not offer the 1.8.0 version of the above package. Try to run with felix framework 5.0.0.