java - OGSi 入门

标签 java eclipse osgi osgi-bundle

我在学习本教程时遇到了一些问题(本应该很简单):

http://www.javaworld.com/article/2077837/java-se/hello--osgi--part-1--bundles-for-beginners.html

最初的问题是存在大量错误,我找不到其来源(但尽管存在错误,程序的输出是正确的)。我读到了关于这个问题的文章:

This usually comes when someone tries to run a Java application against an OSGi bundle with java -classpath .... . It really means that the workbench plug-in hasn't started yet, and so calls to getWorkbench() fail. This is essentially a race condition, and can be solved by either expressing an explicit dependency on that bundle or bumping up that bundle to a higher start level than the workbench. Generally not seen, but if it is, that's what's happening.

我不明白作者提出的第一个解决方案,但我尝试了第二个,但没有成功。然后我到达了教程的第五页(也是最后一页),一切都变得更糟。我尝试按照作者的建议创建服务工厂,但得到的输出不准确。他这样说:

Now try running this sample code. You should notice that it prints the service usage count as one (1) when HelloWorld bundle is started and zero (0) when the HelloWorld bundle is stopped.

但我只得到第一个输出(使用计数器打印为 1),没有其他任何输出。在谷歌搜索时,我发现了第一个问题的可能解决方案,并且我认为它也可以解决第二个问题:

I struggled a lot for “Workbench has not been created yet” the complete day. But I got the solution by the following steps. Go to the Run configuration -> Remove all the target platform jars. Click on add required bundles. Check the org.apache.felix.gogo.runtime, org.apache.felix.gogo.shell, org.eclipse.eqinox.console, org.eclipse.osgi and your jar file. The last and important step. Go to Setting-> check the checkbox of "Clear the configuratation area before launching". Run the OSGi application now.

Enjoy if it works for you as it worked for me.

“删除所有目标平台 jar”是否意味着我应该取消选中“运行配置”中“ bundle ”选项卡中的所有 bundle ?我就是这么做的,而且情况变得更糟。通过这样做,我没有得到任何输出和一些错误(不是像以前那样一堆错误),我将其打印在下面。

!ENTRY org.eclipse.osgi 4 0 2014-02-03 14:50:46.399 !MESSAGE Bundle reference:file:C:/Users/User/workspace/com.javaworld.sample.helloservice@5 not found.

!ENTRY org.eclipse.osgi 2 0 2014-02-03 14:50:46.473 !MESSAGE One or more bundles are not resolved because the following root constraints are not resolved: !SUBENTRY 1 org.eclipse.osgi 2 0 2014-02-03 14:50:46.474 !MESSAGE Bundle initial@reference:file:../../../workspace/com.javaworld.sample.helloworld/ was not resolved. !SUBENTRY 2 com.javaworld.sample.helloworld 2 0 2014-02-03 14:50:46.474 !MESSAGE Missing imported package com.javaworld.sample.service_0.0.0.

!ENTRY org.eclipse.osgi 2 0 2014-02-03 14:50:46.475 !MESSAGE The following is a complete list of bundles which are not resolved, see the prior log entry for the root cause if it exists: !SUBENTRY 1 org.eclipse.osgi 2 0 2014-02-03 14:50:46.475 !MESSAGE Bundle com.javaworld.sample.helloworld_1.0.0.qualifier [2] was not resolved. !SUBENTRY 2 com.javaworld.sample.helloworld 2 0 2014-02-03 14:50:46.475 !MESSAGE Missing imported package com.javaworld.sample.service_0.0.0.

好吧,我以为只要再次选择所有内容(我认为这是以前的样子)我就会重新开始工作,但现在我根本没有任何输出。知道我做错了什么吗?

最佳答案

Does "removing all the target platform jars" mean that I should uncheck all the bundles in the Bundles tab in the Run Configurations? That's what I did, and it just got worse. By doing this, I was getting no output and some errors (not a bunch of them, like before), which I print below.

当您打开 OSGI 配置(“ bundle ”选项卡)时,您可以包含/排除 bundle a) 工作空间 b) 目标平台

“删除所有目标平台jar”表示取消选中“目标平台”节点。

我相信作者的想法是(还没有读过这篇文章)你执行以下操作 1) 检查工作区 bundle - 检查是否包含所有必需的 bundle 2) 取消选中目标平台 bundle 3)单击按钮添加所需的 bundle

通过步骤 1),您将包含所有 bundle 。通过步骤 2) 和 3),包含所有必需的 bundle 。

如果您想使用控制台,请确保 -consoleLog -console 出现在“参数”选项卡上(在“程序参数”下),并且您已包含 org.apache.felix.gogo.runtime、org.apache.felix.gogo.shell、org.eclipse.eqinox.console。

关于java - OGSi 入门,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21529584/

相关文章:

java - bundle 和 jar 之间的 OSGI 和 Maven 依赖关系

java - Spring 数据JPA : Check Exists Entity ID with @Query Annotation

Java - 转义字符串以防止 SQL 注入(inject)

java - 如何在数组中获取动态微调器选择的项目 ID?

apache-flex - 重构时出现 StackOverflowError

java - 如何从命令行运行 osgi 模块?

java - Jersey、osgi 和 Servlet 上下文 3.x

java - 形状未绘制在正确的位置,在其他位置绘制 20-40 像素(使用 MouseListener)

Android 应用程序不是从 Eclipse 启动的

eclipse - 成员变量前缀错误地添加到方法名称