You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@karaf.apache.org by Robert Csakany <ro...@semmi.se> on 2014/10/31 10:54:54 UTC

Re: loading config file from bundle

Hi Mark!

I had same problem before, so I created a ConfigurationLoader bundle for that. You can check out here: https://github.com/liveSense/org.liveSense.misc.configurationLoader
It is uses configurationAdminService to register. The most of the codes came from felix.fileinstall plugin. 

The works:
The project contains a folder in src/main/resources called configuration. It contains .cfg files.

pom.xml
<build>
        <plugins>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Felix-Initial-Configuration>
                            configuration
                        </Felix-Initial-Configuration>
                    </instructions>
                </configuration>
            </plugin>
        </plugins>
    </build>

The format of CFG is same as in file install - which is used by karaf too in /etc folder.

The Felix-Initial-Configuration line will be created on MANIFEST.MF. 
The configurationLoader itself watching bundles, so if there is one that contains Felix-Initial-Configuration, it will load the config files which are presented in the JAR under the configuration folder (or the folder is defined for loading).
 
It is useful when you are want to create specific configurations for customers, developers, qa etc.
A feature you can do some conditional loading of configuration. You can use variables in ${variable} form, which us resolved from system properties, and the configuration is loaded only when the property is presented. 

Another way that you store the configurations in the feature.xml file, but I prefer my way because the developers are separated from feature settings, the releases are centralised in different department.


Regards,

Robert

On 29 Sep 2014, at 20:11, Mark Webb <el...@gmail.com> wrote:

> Thanks Steve.  I will check it out.
> 
> 
> On Mon, Sep 29, 2014 at 10:37 AM, Steve <de...@gmail.com> wrote:
> Mark,
> 
> If you're new to OSGi, you might find "OSGi in Action" from Manning
> Publications to be a great resource.  It provides a solid introduction
> to OSGi in general and the usage of container-provided services (such
> as ConfigurationAdmin).  Additionally, the OSGi specification itself
> is quite readable and offers good insight in regards to expected
> behavior and the motivation behind both core and compendium services.
> 
> 
> Best Regards,
> 
> Steve
> 
> On Thu, Sep 25, 2014 at 5:22 PM, Achim Nierbeck <bc...@googlemail.com> wrote:
> > Hi Mark,
> >
> > yes that's the one :)
> >
> > regards, Achim
> >
> > 2014-09-25 23:03 GMT+02:00 Mark Webb <el...@gmail.com>:
> >>
> >> Achim,
> >>
> >> Thank you.  I was going through the cookbook, just couldn't find good
> >> examples on the loading of configuration files.  I think chapter 2 recipe 6
> >> is what I'm looking for.
> >>
> >>
> >>
> >> On Thu, Sep 25, 2014 at 4:29 PM, Achim Nierbeck <bc...@googlemail.com>
> >> wrote:
> >>>
> >>> Hi Mark,
> >>>
> >>> first of all there is a reasonable amount of samples available. Take a
> >>> look at the manual, and a bit of googling should show you some blogs etc.
> >>> Besides there are already two books covering Apache Karaf available.
> >>> [1][2]
> >>>
> >>> In OSGi you usually use the Configuration Admin service for
> >>> configurations. For this you place your configuration file consisting of
> >>> properties in the etc folder, where the name of the file represents the id
> >>> of the service to configure (filename = service.pid.id.cfg).
> >>> So every time you change the configuration your service is re-configured
> >>> automatically for you.
> >>>
> >>> regards, Achim
> >>>
> >>> [1] -
> >>> https://www.packtpub.com/big-data-and-business-intelligence/learning-apache-karaf
> >>> [2] -
> >>> https://www.packtpub.com/application-development/apache-karaf-cookbook
> >>>
> >>> 2014-09-25 22:14 GMT+02:00 Mark Webb <el...@gmail.com>:
> >>>>
> >>>>
> >>>> I'm just getting into Karaf bundle development.  I've had a hard time
> >>>> finding code examples to get going, so I am using maven to create skeleton
> >>>> projects.  In my bundle, I want to load configuration information which I
> >>>> think I can from a file in the /etc folder.  Where can I find a source code
> >>>> example on how to do this.
> >>>>
> >>>
> >>>
> >>>
> >>> --
> >>>
> >>> Apache Member
> >>> Apache Karaf <http://karaf.apache.org/> Committer & PMC
> >>> OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/> Committer &
> >>> Project Lead
> >>> blog <http://notizblog.nierbeck.de/>
> >>>
> >>> Software Architect / Project Manager / Scrum Master
> >>>
> >>
> >
> >
> >
> > --
> >
> > Apache Member
> > Apache Karaf <http://karaf.apache.org/> Committer & PMC
> > OPS4J Pax Web <http://wiki.ops4j.org/display/paxweb/Pax+Web/> Committer &
> > Project Lead
> > blog <http://notizblog.nierbeck.de/>
> >
> > Software Architect / Project Manager / Scrum Master
> >
>