Home » Java » Enterprise Java » Configure Your OSGi Services with Apache Felix File Install

About Rudiger Herrmann

Configure Your OSGi Services with Apache Felix File Install

A recent post about Managed Services reminded me of a feature in Apache Felix File Install that I found worth mentioning. While working on a project with Holger, I learned from him that File Install cannot only be used to manage bundles. It also monitors configuration files and updates Managed Services when their respective configuration changes.

File Install can also configure Manged Service Factories and more. Yet, I found it particularly useful for Managed Services whose configuration data is usually environment-specific (e.g. printer URLs, database URLs, TCP ports). And the best thing is: it frees you from programmatically fiddling with the Configuration Admin.

How it works

File Install can be told to watch a certain folder (usually through a system property). You can then place configuration files (plain Java property file) into that folder. Configuration files are associated to Managed Services by a naming convention. The file name must have the form <pid>.cfg. If there is a Managed Service with a matching PID, it is updated whenever the file changes.


I put a minimal self-contained example on GitHub. It has a single bundle that provides an EchoService implemented like this:

public class EchoService implements ManagedService {

  public void updated( Dictionary<String, ?> properties ) {
    if( properties != null ) {
      System.out.println( "port = " + properties.get( "port" ) );


Easy to spot: its whole purpose is to print out the configuration whenever it changes.

The EchoService is registered with a PID of echoservice. Besides the bundle is a project that contains the configuration file. It is named echoservice.cfg and holds a single property: port = 7.

The launch configuration puts together the neccessary bundles: OSGi framework (Equinox here), the example bundle, Felix Gogo Shell (to diagnose problems if any) and File Install along with the Configuration Admin. And these VM arguments


tell File Install to watch the project folder and check every Second for changes. Thanks to the project_loc variable the launch configuration is portable across development environments.

Now that we start the OSGi framework, the console output will look like this:

port = 7

If we make a change to echoservice.cfg file and wait a little, we will see that the EchoService is updated. The new configuration appears in the console log.

More of this

If this drew your interest you may want to have a deeper look at File Install. It also supports Managed Service Factories, can write back configuration changes, can substitue property values, and watch multiple folders. The documentation page has all the details.

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!


1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

6. Spring Interview Questions

7. Android UI Design


and many more ....



Leave a Reply

Your email address will not be published. Required fields are marked *


Want to take your Java Skills to the next level?
Grab our programming books for FREE!
  • Save time by leveraging our field-tested solutions to common problems.
  • The books cover a wide range of topics, from JPA and JUnit, to JMeter and Android.
  • Each book comes as a standalone guide (with source code provided), so that you use it as reference.
Last Step ...

Where should we send the free eBooks?

Good Work!
To download the books, please verify your email address by following the instructions found on the email we just sent you.