Engineer999
Engineer999

Reputation: 3945

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. 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

Answers (1)

Milen Dyankov
Milen Dyankov

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

  • Make sure the bundle was properly added to Run Requirements
  • Make sure that auto-resolve on save is checked or click Resolve button enter image description here
  • Make sure resolution does not result in errors and your bundle is added the Run Bundles section.
  • After staring the environment / deploying the bundle, go to Gogo shell and issue 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

Related Questions