I want to deploy all the configuration files of the bundles deployed in karaf be placed in the karaf etc
folder. I want that when the bundles conf files are change are notice by the karaf.
I have a distribution which consist of several features an example of a feature of the XML.I already tried several things e.g. I add the conf file into the feature as below, but this dose not work.
<feature name="gc-backbone-mqtt" version="${linksmart.gc.version}">
<feature version="${linksmart.gc.version}">gc-backbone-router</feature>
<bundle>mvn:org.eclipse.paho/org.eclipse.paho.client.mqttv3/1.0.0</bundle>
<feature version="${linksmart.gc.version}">gc-type-tunnelled</feature>
<configfile finalname="/etc/mqttBackboneProtocol.cfg">mvn:eu.linksmart.gc/backbone.mqtt.impl/${linksmart.gc.version}/mqttprotocol.properties</configfile>
<bundle>mvn:eu.linksmart.gc/backbone.mqtt.impl/${linksmart.gc.version}</bundle>
</feature>
Some of the things I have tried:
http://karaf.922171.n3.nabble.com/OSGi-bundle-configuration-file-td4025438.html
I don't want to copy the file with a specific path as is shown here:
have anyone an idea how to do this?
UPDATE
To achieve that the configuration file get deployed in the etc
folder so the bundle can be reconfigured externally, I have done it in 3 steps:
Building the configuration file: (Works)
To make the config file addressable by Maven I added the following part in the bundle pom. In this way the config file is deploy on the repository:
pom.xml
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>src/main/resources/mqttprotocol.properties</file>
<type>cfg</type>
<classifier>configuration</classifier>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Deploy the file in the karaf etc
(Works)
To deploy the config file in the karaf etc
folder I added the <configfile>
in the feature file as following:
features.xml
<feature name="gc-backbone-mqtt" version="${linksmart.gc.version}">
<feature version="${linksmart.gc.version}">gc-backbone-router</feature>
<bundle>mvn:org.eclipse.paho/org.eclipse.paho.client.mqttv3/1.0.0</bundle>
<bundle>mvn:org.apache.felix/org.apache.felix.fileinstall/3.2.8</bundle>
<configfile finalname="/etc/MQTTBackboneProtocol.cfg">mvn:eu.linksmart.gc/network.backbone.protocol.mqtt.impl/${linksmart.gc.version}/cfg/configuration</configfile>
<feature version="${linksmart.gc.version}">gc-type-tunnelled</feature> <bundle>mvn:eu.linksmart.gc/network.backbone.protocol.mqtt.impl/${linksmart.gc.version}</bundle>
</feature>
Capture configuration change: (not working)
To capture the change of a config file I add the code you suggested (@Donald_W). The problem is that I get just notifications of files are on the folder deploy
but not in etc
. I debug this code and I find out that for the files in etc
are called specifically the "listeners" of those files. I don't know then how I can become a listener of a file deployed in the etc
Eureka!
As I mentioned in the UPDATE the step 1 (build configuration file with maven) and 2 (deploy the conf file etc
) was working but the bundle and the configuration file were not connected. Apparently the reason was that the configuration file was install with another PID as the service which was registering to it. To solve this I registered the ManageService
to the PID of the configurated file deployed. In my case looks as following:
Hashtable <String, Object> properties = new Hashtable<String, Object>();
properties.put(Constants.SERVICE_PID, "MQTTBackboneProtocol");
context.registerService (ManagedService.class.getName(),this , properties);
Where this
is the class which implements the ManageService
and the PID must be the same as is deployed configuration in the etc
, in this case "MQTTBackboneProtocol"
due to the feature definition indicate the configuration file as:
<configfile finalname="/etc/MQTTBackboneProtocol.cfg">mvn:eu.linksmart.gc/network.backbone.protocol.mqtt.impl/${linksmart.gc.version}/cfg/configuration</configfile>