OSGI 缺少需求错误

发布于 2024-12-19 09:44:19 字数 969 浏览 2 评论 0原文

我是 OSGI 新手,我试图弄清楚如何解决以下错误

org.osgi.framework.BundleException: Unresolvedconstraint in bundle org.foo.serviceBundle [253]: Unable to parse 253.0:missing required [ 253.0]包; (&(package=org.slf4j)(version>=1.6.0)(!(version>=2.0.0)))

我使用 Maven 原型来生成捆绑包,并向我的 Activator 类添加一些简单的 slf4j 日志记录。我还使用 Maven 捆绑插件,如下所示:

        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <version>2.2.0</version>
            <extensions>true</extensions>
            <configuration>
                <instructions>
                    <Bundle-Activator>org.shoppingsite.Activator</Bundle-Activator>
                </instructions>
            </configuration>
        </plugin>

我尝试了其他组合,但得到一个或另一个无法解析的包。我正在尝试将捆绑包部署到 GlassFish 应用程序服务器上。任何帮助将不胜感激

谢谢

I am new to OSGI and I am trying to figure out how I resolve errors such as the one below

org.osgi.framework.BundleException: Unresolved constraint in bundle org.foo.serviceBundle [253]: Unable to resolve 253.0: missing requirement [253.0] package; (&(package=org.slf4j)(version>=1.6.0)(!(version>=2.0.0)))

I used a maven archetype to generate a bundle and added some simple slf4j logging to my Activator class. I am also using the maven bundle plugin as follows:

        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <version>2.2.0</version>
            <extensions>true</extensions>
            <configuration>
                <instructions>
                    <Bundle-Activator>org.shoppingsite.Activator</Bundle-Activator>
                </instructions>
            </configuration>
        </plugin>

I have tried other combinations and I get one package or the other that is not resolvable. I am trying to deploy the bundle onto GlassFish appserver. Any help will be appreciated

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

爺獨霸怡葒院 2024-12-26 09:44:19

这通常意味着您缺少导出 org.slf4j 的包。以下是整个工作流程:

  • maven-bundle-plugin 将确保您自己的项目的清单导入 org.slf4j(因为您需要它)。

  • 项目 POM 中的 Maven 依赖项将确保下载 slf4j 工件

那么有两件事可能会出错:

  • 其中之一您的编译失败并且未找到 slf4j 工件(但我想您已经注意到了)

  • 或者您下载的 slf4 工件没有清单,或者没有导出 org.slf4j。要检查它,只需查看 org.slf4j 包的清单即可。如果您直接在 Eclipse 等 IDE 中运行,您可能需要签入 $HOME/.m2/ 来查找工件。

如果您的工件没有正确的清单,您必须找到一些其他可以从中获取正确捆绑包的存储库,或者修改您获得的存储库并将其安装在本地存储库上(并将其部署在您的本地存储库上)本地 Maven 捆绑存储库(例如 Nexus),如果有的话)

最后一件小事:考虑使用 maven-scr 插件,而不是直接定义激活器和服务发现。我希望当我开始使用 OSGi 时就知道这一点!

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!

爱的十字路口 2024-12-26 09:44:19

如果您不想为您使用的每个第 3 方库创建捆绑包,您可以将其编译到捆绑包中。尝试

<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>

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>
年华零落成诗 2024-12-26 09:44:19

我不确定 Grassfish 应用程序服务器。在 Fuse ESB 中添加org.slf4j.*,我们解决了同样的问题。

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

装迷糊 2024-12-26 09:44:19

添加<范围>提供到 POM 中的依赖项。
阅读http://fusesource.com/docs/ide/7.1/release_notes/release_notes。 html

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文