0

I am getting problem when tried to start bundle.

Project structure:

--Main project 
    - sub project 1
    - sub project 2
        src/main/java/util
    - sub project 3
        - bundle project 1
        - bundle project 2
        - bundle project 3

When I compiled main project using Maven install command in eclipse, it's successfully compiled. So, for testing bundle, I have downloaded felix distribution package. I am install bundle successfully but I am not able to start. I getting error dependency cannot be resolved here is my bundle pom file

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <configuration>
                <instructions>
                    <Export-Package>
                        com.test.sub_project_3.step,
                        com.test.sub_project_3.step2
                    </Export-Package>
                    <Import-Package>*
                        org.osgi.framework,
                        org.osgi.util.tracker,
                        com.test.sub_project_2.util
                    </Import-Package>
                    <Embed-Dependency>
                        slf4j-api;scope=compile
                    </Embed-Dependency>
                    <Bundle-Activator>com.test.sub_project_3.osgi.Activator</Bundle-Activator>
                </instructions>
            </configuration>
        </plugin>
    </plugins>
</build>

I am getting error for "com.test.sub_project_2.util cannot be resolved". com.test.sub_project_2 it'sussfully compiled and packag name it's also correct but still I don't understand why I am getting error.

Hkachhia
  • 4,463
  • 6
  • 41
  • 76

1 Answers1

1

You must understand that OSGi and Maven are different tools with different strategies concerning package resolution. At design time, maven strategy is used. You indicate your dependency in your POM file. Moreover in your case you used the maven bundle plug in , so you can constrain which package needs to be imported at runtime by your bundle (your import-package section). So in your case, all dependencies are present at design time because your project compiles. But it not implies that the runtime resolution will work, because at runtime OSGi resolution is used.

In your case the error message indicates that your deployed bundle cannot find at runtime the com.test.sub_project_2.util in order to be executed. This is because no bundle present in the OSGi distribution provides the package. So you can bundlify the project that contains the package and deploy it in your OSGi distrib. If you do that the package is now available at runtime.

In a simplistic way you can think as this problem in this way: The classpath used for your bundle is different at design and runtime. And you cannot assume a causality relation between them.

Regards

colin aygalinc
  • 457
  • 4
  • 13
  • com.test.sub_project_2.util is Jar project and I want to use it in bundle. So how can I use JAR project in bundle ? – Hkachhia May 31 '17 at 05:05
  • 1
    You have several choices: - Create a project that bundlify the jar in a bundle and deploy this bundle, i think this solution is more OSGi friendly. - Remove com.test.sub_project_2.util from the import package section and modify the embed dependency section in order to embeded the package in your own jar. ( Something like *;scope=compile;inline=true will do the trick if you add the compile to the dependency that provides the package). More internet search will give you a exhaustive list of solution. – colin aygalinc Jun 01 '17 at 09:37