OSGI missing requirement error

≡放荡痞女 提交于 2019-11-30 09:34:37

This usually means that you're missing a bundle that exports org.slf4j. Here's the whole workflow:

  • The maven-bundle-plugin will make sure that your own project's manifest imports org.slf4j (since you need it).

  • The maven dependencies in your project's POM will make sure that the slf4j artifact is downloaded

Then 2 things can go wrong:

  • either your compilation failed and the slf4j artifact wasn't found (but I suppose you'd have noticed that)

  • or the slf4 artifact you downloaded does not have a Manifest or is not exporting org.slf4j. To check it out, simply look into the manifest of the org.slf4j bundle. If you are running things directly in an IDE like eclipse, you might want to check in $HOME/.m2/ instead to find the artifact.

If your artifact doesn't have a proper manifest, you'll have to either find some other repo you can get a proper bundle from, or modify the one you're getting and installing it on your local repository (and deploying it on your local maven bundle repository (e.g. nexus) if you have one)

Last little thing: consider using the maven-scr plugin instead of directly defining activators and service discovery. I wish I had known that when I started with OSGi!

If you don't want to go through the trouble of creating bundles for every 3rd party library that you use you can compile it into your bundle. Try

<plugin>
    <groupId>org.apache.felix</groupId>
    <artifactId>maven-bundle-plugin</artifactId>
    <version>2.3.6</version>
    <extensions>true</extensions>
    <configuration>
        <instructions>
            <Bundle-Activator>org.shoppingsite.Activator</Bundle-Activator>
            <Embed-Dependency>
                slf4j-api;scope=compile,
                log4j;scope=compile
            </Embed-Dependency>
        </instructions>
    </configuration>
</plugin>

I am not sure about Grassfish appserver. In Fuse ESB by adding <Import-Package> org.slf4j.*</Import-Package>, we resolved the same issue.

Add <scope>provided</scope> to dependencies in the POM. Read http://fusesource.com/docs/ide/7.1/release_notes/release_notes.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!