Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 494687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:31:10+00:00 2026-05-13T05:31:10+00:00

I can’t find information about starting and using Apache Felix from code. I want

  • 0

I can’t find information about starting and using Apache Felix from code.

I want do things which I am able (or unable 😉 ) to do with Apache Felix’s Shell.

For example, how do I start a module?

Please help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T05:31:10+00:00Added an answer on May 13, 2026 at 5:31 am

    So, after trying around a lot of time, here’s a possible solution.

    We will have two projects:

    • OsgiModuleA, which contains a module-to-be-started
    • OsgiUsage, which will use the “Module A”

    Project OsgiModuleA

    File module/a/Activator.java

    package module.a;
    
    import org.osgi.framework.*;
    
    public class Activator
        implements BundleActivator, ServiceListener {
    
      @Override
      public void start(BundleContext bc)
          throws Exception {
    
        System.out.println("*** started");
        bc.addServiceListener(this);
      }
    
      @Override
      public void stop(BundleContext bc)
          throws Exception {
    
        bc.removeServiceListener(this);
        System.out.println("*** stopped");
      }
    
      @Override
      public void serviceChanged(ServiceEvent se) {
        String s;
    
        switch (se.getType()) {
          case ServiceEvent.MODIFIED:
            s = "modified";
            break;
          case ServiceEvent.REGISTERED:
            s = "registered";
            break;
          case ServiceEvent.UNREGISTERING:
            s = "unregistered";
            break;
          default:
            s = "unknown";
        }
    
        System.out.println("= = = service changed: " + s);
      }
    
    }
    

    File manifest.mf

    Manifest-Version: 1.0
    X-COMMENT: Main-Class will be added automatically by build
    Bundle-Name: Module A
    Bundle-Description: Module A
    Bundle-Vendor: me
    Bundle-Version: 1.0.0
    Bundle-Activator: module.a.Activator
    Import-Package: org.osgi.framework
    

    Project OsgiUsage

    File usage/Main.java

    package usage;
    
    import java.util.*;
    import org.apache.felix.framework.*;
    import org.apache.felix.framework.util.*;
    import org.osgi.framework.*;
    
    public class Main {
    
      static class HostActivator
          implements BundleActivator {
    
        private BundleContext context = null;
    
        @Override
        public void start(BundleContext bc) {
          context = bc;
        }
    
        @Override
        public void stop(BundleContext bc) {
          context = null;
        }
    
        public BundleContext getContext() {
          return context;
        }
    
      }
    
      public static void main(String[] args)
          throws Exception {
    
        Map<String, Object> map = new HashMap<String, Object>();
    
        map.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA,
            "some.module.i.dont.know; version=1.0.0");
    
        HostActivator activator = new HostActivator();
    
        List<Object> list = new LinkedList<Object>();
        list.add(activator);
        map.put(FelixConstants.SYSTEMBUNDLE_ACTIVATORS_PROP, list);
    
        Felix f = new Felix(map);
    
        System.out.println("starting OSGI...");
        f.start();
    
        Bundle b = f.getBundleContext().installBundle(
            "file:../OsgiModuleA/dist/OsgiModuleA.jar"); // dirty path ;)
        String bName = b.getLocation();
    
        System.out.println("starting bundle " + bName);
        b.start();
    
        Set<String> inUse = new HashSet<String>();
        for (ServiceReference sr : f.getServicesInUse()) {
          inUse.add(sr.toString());
        }
        for (ServiceReference sr : f.getRegisteredServices()) {
          String flag = (inUse.contains(sr.toString()) ? "[in use]" : "[      ]");
          System.out.println("+ registered service: " + flag + " " + sr.toString());
        }
    
        System.out.println("stopping bundle " + bName);
        b.stop();
    
        System.out.println("uninstalling bundle " + bName);
        b.uninstall();
    
        System.out.println("stopping...");
        f.stop();
        f.waitForStop(1000);
      }
    
    }
    

    Output

    starting OSGI...
    starting bundle file:../OsgiModuleA/dist/OsgiModuleA.jar
    *** started
    + registered service: [in use] [org.osgi.service.startlevel.StartLevel]
    + registered service: [      ] [org.osgi.service.packageadmin.PackageAdmin]
    stopping bundle file:../OsgiModuleA/dist/OsgiModuleA.jar
    *** stopped
    uninstalling bundle file:../OsgiModuleA/dist/OsgiModuleA.jar
    stopping...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 241k
  • Answers 241k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Take a look at OverLib. It is an open source… May 13, 2026 at 7:29 am
  • Editorial Team
    Editorial Team added an answer You could use: WHERE ROWNUM <= :NUM ...but the table… May 13, 2026 at 7:29 am
  • Editorial Team
    Editorial Team added an answer It's essential. Log all errors with related data (method args… May 13, 2026 at 7:29 am

Related Questions

I want use html5's new tag to play a wav file (currently only supported
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
In order to apply a triggered animation to all ToolTip s in my app,
I've got a string that has curly quotes in it. I'd like to replace
I am currently running into a problem where an element is coming back from

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.