Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Run Java Class on Bundle Start

Level 2
Level 2


Is there a way to run a java class on a bundle start up like a main class?

1 Reply
Level 2
Level 2

You can put an OSGi service component inside the bundle and in activate method of the service component you can run your java class.


import org.apache.felix.scr.annotations.Activate;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Service;



public class MyApplicationStarterService{

  protected void activate(ComponentContext ctx) {

      MyAppClass app = new MyAppClass();;




This isn't exactly answering the question, because the activation of this component is lazy, and thus is asynchronous to the activation of a bundle.

Instead you should specify a BundleActivator in the metadata of your OSGI bundle. The code of this class is executed during the bundle start (also meaning, that an unhandled exception in the BundleActivator prevents the bundle from starting.

The definition in the POM: acs-aem-commons/pom.xml at master · Adobe-Consulting-Services/acs-aem-commons · GitHub

The BundleActivator class: acs-aem-commons/ at master · Adobe-Consulting-Services/acs-aem-commons · GitHub