Reputation: 3945
I am new to the Java OSGi framework and have inherited a project which needs new functionality. The project has multiple bundles and is set up to run on Eclipse with all the required plugins etc.
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.
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.
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");
}
}
Upvotes: 0
Views: 609
Reputation: 3052
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:
@Component(immediate = true)
public class ExampleProviderImpl
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
auto-resolve on save
is checked or click Resolve
button Run Bundles
section. lb
command. Make sure your bundle is Active
If something goes wrong on during any of those steps please update the question with all relevant information.
Upvotes: 1