java 启动 OSGi 包

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3447419/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 01:54:50  来源:igfitidea点击:

Starting OSGi bundle

javaosgibundleequinox

提问by EK.

I try to run OSGi plug in in Eclipse. It is empty bundle, but eclipse always send me errors There are my console messages http://pastebin.com/dqQfpQhdWhat is wrong?

我尝试在 Eclipse 中运行 OSGi 插件。它是空包,但 eclipse 总是向我发送错误有我的控制台消息 http://pastebin.com/dqQfpQhd 有什么问题?

采纳答案by garamond

The problem is that the default target includes many bundles that have nothing to do with your bundle -- typing the command sswhen all the error messages have finished will list them.

问题是默认目标包括许多与您的包无关的包——ss在所有错误消息完成后输入命令将列出它们。

Here's what you do:

这是你要做的:

  1. In Eclipse, go to Preferences > Plug-in Development > Target Platform
  2. Create a new empty target definition
  3. In the Locations tab, add a directory containing nothing but the Equinox bundle (which you can copy from the plugins directory of your Eclipse installation, the jar is named something like org.eclipse.osgi_3.7.0.v20110613.jar)
  4. Make sure the new target is active and try running your bundle again
  1. 在 Eclipse 中,转到首选项 > 插件开发 > 目标平台
  2. 创建一个新的空目标定义
  3. 在 Locations 选项卡中,添加一个只包含 Equinox 包的目录(您可以从 Eclipse 安装的插件目录中复制该包,该 jar 的名称类似于 org.eclipse.osgi_3.7.0.v20110613.jar)
  4. 确保新目标处于活动状态并再次尝试运行您的包

回答by Shivam

I struggled a lot for “Workbench has not been created yet”the complete day.

我一整天都在“工作台尚未创建”而苦苦挣扎。

But I got the solution by the following steps.-

但我通过以下步骤得到了解决方案.-

  1. Go to the Run configuration-> Remove all the target platform jars.
  2. Click on add required bundles.
  3. Check the org.apache.felix.gogo.runtime, org.apache.felix.gogo.shell, org.eclipse.eqinox.console, org.eclipse.osgi and your jar file.
  4. The last and important step. Go to Setting-> checkthe checkbox of "Clear the configuratation area before launching".
  5. Run the OSGi application now.
  6. Enjoy if it works for you as it worked for me.
  1. 转到运行配置-> 删除所有目标平台 jar。
  2. 单击添加所需的捆绑包。
  3. 检查 org.apache.felix.gogo.runtime、org.apache.felix.gogo.shell、org.eclipse.eqinox.console、org.eclipse.osgi 和您的 jar 文件。
  4. 最后一步也是重要的一步。进入设置->检查的复选框“发射前清除configuratation区”。
  5. 现在运行 OSGi 应用程序。
  6. 如果它对你有用,就像对我有用一样,那就享受吧。

Thanks

谢谢

回答by Andreas Dolk

This is the main problem:

这是主要问题:

java.lang.IllegalStateException: Workbench has not been created yet.

java.lang.IllegalStateException:尚未创建工作台。

You're using methods/objects from the workbench or related to the workbench while the workbench itself has not been created yet. Maybe you can delay the activation of the bundle or remove 'workbench' dependencies from the activation/initialisation part of the bundle.

您正在使用工作台中或与工作台相关的方法/对象,而工作台本身尚未创建。也许您可以延迟捆绑包的激活或从捆绑包的激活/初始化部分中删除“工作台”依赖项。



Yikes, back to the beginning. The last line of the log containes a 'Hello World' - is this the expected output from your bundle? Maybe it's not your bundle that causes the errors and warnings on the output. I see some 'mylin' and other stuff too. If possible, add another clean installation of eclipse (no additional bundles/plugins) to your system and try the bundle in that environment.

咳咳,回到开头。日志的最后一行包含一个“Hello World”——这是你的包的预期输出吗?也许导致输出错误和警告的不是你的包。我也看到了一些“mylin”和其他东西。如果可能,在您的系统中添加另一个全新安装的 eclipse(没有额外的包/插件)并在该环境中尝试该包。



From a good article on eclipsezone:

来自一篇关于 eclipsezone好文章

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 levelthan the workbench. Generally not seen, but if it is, that's what's happening.

当有人尝试使用 java -classpath .... 对 OSGi 包运行 Java 应用程序时,通常会出现这种情况。这实际上意味着工作台插件尚未启动,因此对 getWorkbench() 的调用失败。这本质上是一个竞争条件,可以通过表达对该包的显式依赖或将该包提升到比工作台更高的起始级别来解决。通常看不到,但如果是,那就是正在发生的事情。

What's the superclass of your own bundle? Because that could introduce a dependency on the workbench.

你自己的bundle的超类是什么?因为这可能会引入对工作台的依赖。

And - how do 'start' the bundle, from within eclipse or hav you jar'ed it up and put it in the eclipse plugin folder? That could make a difference too.

以及 - 如何从 eclipse 中“启动”捆绑包,或者您是否将其打包并放入 eclipse 插件文件夹中?这也可能有所作为。

回答by Neil Bartlett

None of those errors have anything to do with your bundle. As you can see from the "Hello World" output, your bundle is starting just fine.

这些错误都与您的捆绑包无关。正如您从“Hello World”输出中看到的,您的包启动得很好。

I believe you are launching Eclipse in the wrong way, probably eagerly activating all the bundles. Eclipse needs to start with most workbench bundles in "lazy activation" mode.

我相信您以错误的方式启动 Eclipse,可能急切地激活所有捆绑包。Eclipse 需要以“延迟激活”模式启动大多数工作台包。

  1. Please specify how you are launching Eclipse. Did you add -consoleto the eclipse.inifile?
  2. Does this problem occur when you do NOT try to use your own bundle?
  3. How are you installing and activating your own bundle?
  4. Please paste the following files:
    • The MANIFEST.MFfrom your own bundle
    • config.inifrom ECLIPSE_HOME/configuration
    • eclipse.inifrom ECLIPSE_HOME
  1. 请指定您如何启动 Eclipse。你添加-consoleeclipse.ini文件中了吗?
  2. 当您不尝试使用自己的捆绑包时会出现此问题吗?
  3. 您如何安装和激活自己的捆绑包?
  4. 请粘贴以下文件:
    • MANIFEST.MF从自己的包
    • config.iniECLIPSE_HOME/configuration
    • eclipse.iniECLIPSE_HOME

回答by Krumelur

Try to do this before running your bundle:

在运行您的捆绑包之前尝试执行此操作:

if(!PlatformUI.isWorkbenchRunning()) {
    PlatformUI.createAndRunWorkbench(PlatformUI.createDisplay(), new WorkbenchAdvisor() {...}); 
}

回答by Markus Lausberg

First check the dependencies of the empty plugin. May be you are missing to add a plugin, whcih is not loaded at runtime.

首先检查空插件的依赖关系。可能是您缺少添加插件,在运行时未加载该插件。

If you have dependencies in your plugin, check hich version of the plugins are used.

如果您的插件中有依赖项,请检查使用的插件的高版本。

Which Java version you have defined in your plugin? Is it higher, than the version you are using at runtime?

您在插件中定义了哪个 Java 版本?它是否高于您在运行时使用的版本?

Is your plugin loading DLLs? if so, check whether the DLL can be found at runtime.

您的插件是否正在加载 DLL?如果是,请检查是否可以在运行时找到该 DLL。

Edit:

编辑:

# Workbench has not been created yet. # at org.eclipse.ui.PlatformUI.getWorkbench(PlatformUI.java:92) # at org.eclipse.mylyn.internal.monitor.ui.MonitorUiPlugin.start(MonitorUiPlugin.java:145)

# 工作台尚未创建。# 在 org.eclipse.ui.PlatformUI.getWorkbench(PlatformUI.java:92) # 在 org.eclipse.mylyn.internal.monitor.ui.MonitorUiPlugin.start(MonitorUiPlugin.java:145)

What did you define in the start method of the Activator? It sems, that you are using the workbench which is not created yet.

你在 Activator 的 start 方法中定义了什么?看来,您正在使用尚未创建的工作台。