Title: Karaf add additional property to existing config file
Tags: osgi;apache-karaf;karaf;blueprint-osgi
Question: I have a bundle which uses a configuration file ```org.jemz.karaf.tutorial.hello.service.config.cfg``` with one property:

```org.jemz.karaf.tutorial.hello.service.msg="I am a HelloServiceConfig!!"
```

My blueprint for using ConfigAdmin is like:

```<cm:property-placeholder persistent-id="org.jemz.karaf.tutorial.hello.service.config" update-strategy="reload" &gt;
    <cm:default-properties&gt;
        <cm:property name="org.jemz.karaf.tutorial.hello.service.msg" value="Hello World!"/&gt;
</cm:default-properties&gt;
</cm:property-placeholder&gt;



<bean   id="hello-service-config"
        class="org.jemz.karaf.tutorial.hello.service.config.internal.HelloServiceConfig"
        init-method="startup"
        destroy-method="shutdown"&gt;

    <property name="helloServiceConfiguration"&gt;
        <props&gt;
              <prop key="org.jemz.karaf.tutorial.hello.service.msg" value="${org.jemz.karaf.tutorial.hello.service.msg}"/&gt;
        </props&gt;
    </property&gt;
</bean&gt;

<service ref="hello-service-config" interface="org.jemz.karaf.tutorial.hello.service.IHelloService" /&gt;
```

This works fine as long as I can change the value of the property and the bundle automatically updates the property.

I am wondering if there's any way of adding a new property to my config file without having to change the blueprint (which involves compile/package again).Of course my bundle should be ready to handle new properties.

Not sure if this makes sense in OSGi. Can anyone give me a hint of how to dynamically add new properties to an existing configuration file and make them available in ConfigAdmin?


Here is the accepted answer: @yodamad showed me that properties were being updated in my ConfigurationAdmin service, but unfortunately my bundel was not receiving the new properties because in the bean definition I was just using a fixed property.

Finally in order to get new properties from config files I have changed my blueprint definition as follows:

```<cm:property-placeholder persistent-id="org.jemz.karaf.tutorial.hello.service.config" update-strategy="reload" &gt;
</cm:property-placeholder&gt;

<bean   id="hello-service-config"
        class="org.jemz.karaf.tutorial.hello.service.config.internal.HelloServiceConfig"
        init-method="startup"
        destroy-method="shutdown"&gt;
</bean&gt;

<service ref="hello-service-config" interface="org.jemz.karaf.tutorial.hello.service.IHelloService" /&gt;


<reference id="hello-service-config-admin" interface="org.osgi.service.cm.ConfigurationAdmin"
           availability="optional"&gt;
    <reference-listener bind-method="setConfigAdmin"
                        unbind-method="unsetConfigAdmin"&gt;
        <ref component-id="hello-service-config"/&gt;
    </reference-listener&gt;
</reference&gt;
```

I have a reference to the ConfigurationAdmin service so, now I can check all properties for my bundle as:

```public void setConfigAdmin(ConfigurationAdmin cfgAdmin) {
    this.cfgAdmin = cfgAdmin;
    try {
        Configuration cfg =   cfgAdmin.getConfiguration("org.jemz.karaf.tutorial.hello.service.config");
        Dictionary<String, Object&gt; properties = cfg.getProperties();
        Enumeration<String&gt; en = properties.keys();
        while(en.hasMoreElements()) {
            String key = en.nextElement();

            System.out.println("KEY: " + key + " VAL: " + properties.get(key));
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}
```

As my 'update-strategy' is ```reload``` I can get updated whenever a new ConfigurationAdmin service is registered.

Any comment about my approach is welcome!

Comment for this answer: You can also use  have a class that `implements ConfigurationListener, BundleContextAware` interfaces. Then you'll receive all events regarding configuration changes, thus you can process whatever you want in your application

Here is another answer: You can add a property in karaf shell :

1/ ```config:edit org.jemz.karaf.tutorial.hello.service.config```

2/ ```config:propset <key&gt; <value&gt;```

3/ finally ```config:update``` to save change to file.

If you want to do it programatically, check karaf source to see the implementation

Comment for this answer: Hi Jorge, if you are using SpringDM I can give you sample of configuration to be able to have multiple configuration files managed for one bundle
Comment for this answer: Thanks for the answer. Your solution works, the properties are stored in the Properties place holder and I can list them. The problem is that my bundle cannot get those new properties. I think it is related to the bean definition I have only set one property to be injected "org.jemz,karaf.tutorial.service.msg" thus I cannot get more properties in my `setHelloServiceConfiguration` method. I have figured out another way of getting new properties from my config files I will post it in my answer. Anyway I will give you an upvote for the idea

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2015:00:10/09/15', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<osgi><apache-karaf><karaf><blueprint-osgi>', 'Title': 'Karaf add additional property to existing config file', 'ViewCount': 2619, 'id': 33043163, 'user_AboutMe': '<p>I am a full stack developer focused on micro-services deployed on OSGi frameworks (Apache Karaf). As front-ends I use AngularJS, JQuery, Bootstrap. I am a technology enthusiast now learning MongoDB, Node.JS.... My current OS is Archlinux.</p>\n', 'user_AccountId': 6268375.0, 'user_DisplayName': 'Jorge Martinez', 'user_Reputation': 1191.0, 'user_Views': 114.0, 'user_id': 4873300.0}}