[英]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
检查是否确实如此
Run Requirements
Run Requirements
auto-resolve on save
is checked or click Resolve
button auto-resolve on save
或单击“ Resolve
按钮 Run Bundles
section. Run Bundles
部分。 lb
command. 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.