简体   繁体   English

OSGi-如何获取新的捆绑包以通过现有的bndrun文件运行

[英]OSGi - How to get a new bundle to run via an existing bndrun file

I am new to the Java OSGi framework and have inherited a project which needs new functionality. 我是Java OSGi框架的新手,并且继承了一个需要新功能的项目。 The project has multiple bundles and is set up to run on Eclipse with all the required plugins etc. 该项目具有多个捆绑软件,并设置为可在Eclipse上使用所有必需的插件等运行。

There is a start.bndrun file which when run via the "Run OSGi" option on Eclipse, starts off the main application and runs all the bundles via the their activate() functions. 有一个start.bndrun文件,当通过Eclipse上的“运行OSGi”选项运行该文件时,它将启动主应用程序,并通过其activate()函数运行所有捆绑软件。

The problem is, when I create my own simple component and bundle as below, ExampleProviderImpl, export the required packages etc. and try to add it to the "Run Bundles" option of start.bndrun , it just doesn't seem to run. 问题是,当我如下创建我自己的简单组件和包,ExampleProviderImpl,导出所需的包等并将其添加到start.bndrun的“运行包”选项中 ,它似乎并没有运行。

package Test;

import org.osgi.service.component.annotations.Activate;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;

@Component
public class ExampleProviderImpl
{

   @Activate
   void activate()
   {
      System.out.println("HELLO FROM ExampleProviderImpl.class");
      System.out.println("HELLO FROM ExampleProviderImpl.class");
      System.out.println("HELLO FROM ExampleProviderImpl.class");
      System.out.println("HELLO FROM ExampleProviderImpl.class");
      System.out.println("HELLO FROM ExampleProviderImpl.class");
   }
}

I assume by 我假设

it just doesn't seem to run. 它似乎没有运行。

you mean that nothing gets printed out. 您的意思是什么也没打印出来。 If so that is most likely because components are by default lazy and will not be activated until they are needed. 如果是这样,则最有可能是因为默认情况下组件是惰性的,只有在需要它们时才会被激活。 Try adding immediate = true to your annotation to force component activation: 尝试在注释中添加immediate = true以强制激活组件:

@Component(immediate = true)
public class ExampleProviderImpl

UPDATE UPDATE

The above assumes the bundle was properly added, resolved and started in the runtime. 上面假设捆绑包在运行时已正确添加,解析和启动。 To check if that is indeed the case 检查是否确实如此

  • Make sure the bundle was properly added to Run Requirements 确保捆绑软件已正确添加到Run Requirements
  • Make sure that auto-resolve on save is checked or click Resolve button 确保选中auto-resolve on save或单击“ Resolve按钮 在此处输入图片说明
  • Make sure resolution does not result in errors and your bundle is added the Run Bundles section. 确保解决方案不会导致错误,并且已将捆绑软件添加到Run Bundles部分。
  • After staring the environment / deploying the bundle, go to Gogo shell and issue lb command. 在注视环境/部署捆绑包之后,转到Gogo shell并发出lb命令。 Make sure your bundle is Active 确保您的捆绑包处于Active

If something goes wrong on during any of those steps please update the question with all relevant information. 如果在这些步骤中的任何一个步骤中出现问题,请使用所有相关信息更新问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM