javaosgiosgi-bundlemaven-bundle-pluginembedded-osgi

Embedding javassist dependency breaks OSGi bundle


I am trying an embedded Felix scenario. While loading a bundle from the embedded OSGi container (Apache Felix), I am getting the following error.

org.osgi.framework.BundleException: Unable to resolve test.bundle-attempt [50](R 50.0): missing requirement [test.bundle-attempt [50](R 50.0)] osgi.wiring.package; (osgi.wiring.package=com.sun.jdi.connect) Unresolved requirements: [[test.bundle-attempt [50](R 50.0)] osgi.wiring.package; (osgi.wiring.package=com.sun.jdi.connect)]
    at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:4362)
    at org.apache.felix.framework.Felix.startBundle(Felix.java:2277)
    at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1535)
    at org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:308)
    at java.lang.Thread.run(Thread.java:745)

With some trial and error, I have found that introducing javassist causes the error.

        <dependency>
            <groupId>org.javassist</groupId>
            <artifactId>javassist</artifactId>
            <version>3.25.0-GA</version>
        </dependency>

I am trying to embed the dependency.

            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
                        <Bundle-Name>${project.artifactId}</Bundle-Name>
                        <Bundle-Version>${project.version}</Bundle-Version>
                        <Bundle-Activator>com.snc.TestPluginsActivator</Bundle-Activator>
                        <Embed-Dependency>*;scope=compile|runtime;inline=true</Embed-Dependency>
                        <Export-Package>com.snc</Export-Package>
                        <Embed-Transitive>true</Embed-Transitive>
                    </instructions>
                </configuration>
            </plugin>

Any suggestions on the reason why I am getting this error ?


Solution

  • the javassist artifact is dependent on jar

    <groupId>com.sun</groupId>
    <artifactId>tools</artifactId>
    

    and the above jar is marked as optional in the pom of javassist and the package com.sun.jdi.connect which is unresolved in your example belongs to the above jar, tools, that I mentioned.

    When trying get the transtive dependencies of Embed-dependencies, maven-bundle-plugin doesn't mark the packages of those transtive optional dependencies as optional in MANIFEST.MF file and it is trying to resolve the dependencies when the bundle is installed. As the optional transtive dependencies are not included in the class path of the bundle it is throwing the error saying Unresolved requirements while starting the bundle.

    To resolve the issue you can mark those dependencies as optional in the pom of bundle.