I have a Java application built with OSGi that I want to run in different modes, say a remote & local data source. I would like to be able to build and deploy a single version so that I could run the app as a service in remote mode and then stop the service & try different things in local mode.
I am using declarative services.
Would there be a way to do this?
# app -remote
Starting app in remote mode
Disabling com.example.data.local.FileStoreDao
Enabling com.example.data.remote.MySqlDao
...
And conversely:
# app -local
Starting app in localmode
Disabling com.example.data.remote.MySqlDao
Enabling com.example.data.local.FileStoreDao
...
Or something similar.
Not sure what framework you’re using, but in Equinox, you can pass a different config file with a command line swich:
http://www.eclipse.org/equinox/documents/quickstart-framework.php
You could have two config files, and have a wrapper (java or batch file?) around the OSGi bootstrapper to select the proper config file. I have done something like this, but in my case I ended up going with two distros with different plugins, as it was simpler and it was all that I needed. Hope this helps