You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Henrik Niehaus <he...@gmx.de> on 2009/08/14 17:28:33 UTC
Using OBR in host application
Hi Felix users,
I'm trying to use the OBR service in an application, which embeds felix.
This is what I'm doing:
1. Start the framework in the host application:
private void startOsgiFramework() {
// Create a case-insensitive configuration property map.
Map<String, Object> configMap = new HashMap<String, Object>();
// Add the bundle provided service interface package and the
core OSGi
// packages to be exported from the class path via the system
bundle.
configMap.put(BundleCache.CACHE_ROOTDIR_PROP, "cache");
configMap.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA,
"net.sf.jmp3renamer," +
"net.sf.jmp3renamer.gui," +
"net.sf.jmp3renamer.util," +
"net.sf.jmp3renamer.plugins," +
"net.sf.jmp3renamer.gui.components.historycombobox," +
"org.slf4j;version=\"1.5\"");
// add the mandatory bundles
StringBuffer sb = new StringBuffer();
File[] bundles = new File("../../bundle").listFiles();
for (int i = 0; i < bundles.length; i++) {
File bundle = bundles[i];
sb.append("file:").append(bundle.getAbsolutePath()).append(' ');
}
String autoStart = sb.toString();
logger.debug("Auto start packages: {}", autoStart);
configMap.put(AutoActivator.AUTO_START_PROP + ".1", autoStart);
configMap.put(FelixConstants.LOG_LEVEL_PROP, "3");
// Create list to hold custom framework activators.
List<BundleActivator> list = new ArrayList<BundleActivator>();
// Add activator to process auto-start/install properties.
list.add(new AutoActivator(configMap));
list.add(this);
// Add activators to the configuration map.
configMap.put(FelixConstants.SYSTEMBUNDLE_ACTIVATORS_PROP, list);
try {
// Now create an instance of the framework with
// our configuration properties and activator.
m_felix = new Felix(configMap);
// Now start Felix instance.
m_felix.start();
m_felix.getBundleContext();
filePluginTracker = new FilePluginTracker(bndCtx,
FilePlugin.class.getName(), null);
filePluginTracker.open();
dataPluginTracker = new DataPluginTracker(bndCtx,
DataPlugin.class.getName(), null);
dataPluginTracker.open();
generalPluginTracker = new GeneralPluginTracker(bndCtx,
GeneralPlugin.class.getName(), null);
generalPluginTracker.open();
} catch (Exception ex) {
logger.error("Could not start osgi framework", ex);
System.exit(1);
}
}
2. Try to get the OBR service:
BundleContext ctx = Main.getBundleContext();
ServiceReference sr =
ctx.getServiceReference(RepositoryAdmin.class.getName());
RepositoryAdmin adm = (RepositoryAdmin) ctx.getService(sr);
I'm getting a ClassCastException, when I try to get the service from the
bundle context:
java.lang.ClassCastException:
org.apache.felix.bundlerepository.RepositoryAdminImpl cannot be cast to
org.osgi.service.obr.RepositoryAdmin.
This sounds reasonable to me, because the interface class
(RepositoryAdmin) gets loaded by the application's loader and the
RepositoryAdminImpl comes from the obr bundle loader, which has also
loaded the interface. So there are two "versions" of the interface and
the cast doesn't work.
But what can I do in such a situation? What's best practice for using
bundle services in the host application?
Regards
Henrik
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org
Re: Using OBR in host application
Posted by Henrik Niehaus <he...@gmx.de>.
Richard S. Hall schrieb:
> On 8/14/09 14:04, Henrik Niehaus wrote:
>> Richard: Thanks for the link. I actually didn't find this page before.
>> I'm wondering if it is accessible through the felix home page, because I
>> was looking for an example like this clicking all the links under
>> documentation...
>>
>
> Documents->Subprojects->Apache Felix Framework->Apache Felix Framework
> Launching and Embedding
Makes sense, but nevertheless it's hard to find. At least for me :)
>
>> P.S.: I didn't subscribe to the list, so I didn't get your answer and
>> couldn't respond directly to your mail. Sorry for that.
>>
>
> Perhaps it is a good idea to subscribe to the lists from which you are
> trying to get help so you can receive it! ;-)
Usually I use gmane to access mailing lists, because it's more feed
like. But the felix user mailing list is not available through gmane :(
. For the next question, which will certainly appear, I will subscribe
to the list.
>
> -> richard
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
>> For additional commands, e-mail: users-help@felix.apache.org
>>
>>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org
Re: Using OBR in host application
Posted by "Richard S. Hall" <he...@ungoverned.org>.
On 8/14/09 14:04, Henrik Niehaus wrote:
> Richard: Thanks for the link. I actually didn't find this page before.
> I'm wondering if it is accessible through the felix home page, because I
> was looking for an example like this clicking all the links under
> documentation...
>
Documents->Subprojects->Apache Felix Framework->Apache Felix Framework
Launching and Embedding
> P.S.: I didn't subscribe to the list, so I didn't get your answer and
> couldn't respond directly to your mail. Sorry for that.
>
Perhaps it is a good idea to subscribe to the lists from which you are
trying to get help so you can receive it! ;-)
-> richard
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org
Re: Using OBR in host application
Posted by Henrik Niehaus <he...@gmx.de>.
Richard: Thanks for the link. I actually didn't find this page before.
I'm wondering if it is accessible through the felix home page, because I
was looking for an example like this clicking all the links under
documentation...
P.S.: I didn't subscribe to the list, so I didn't get your answer and
couldn't respond directly to your mail. Sorry for that.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org
RE: How does your development environment look like?
Posted by "Edelson, Justin" <Ju...@mtvstaff.com>.
One thing I've been using a lot lately is the sling Maven plugin,
specifically the install goal. I bind this to the Maven install phase.
This allows me to start up Felix with the Web Console running and simply
run 'mvn install' (or the corresponding menu item in Eclipse) and get my
project built and bundle installed into Felix.
You could actually do something similar with file install, i.e. use the
antrun Maven plugin in the install phase to copy the bundle to the file
install watch folder.
Justin
-----Original Message-----
From: Henrik Niehaus [mailto:henrik.niehaus@gmx.de]
Sent: Friday, August 14, 2009 12:46 PM
To: users@felix.apache.org
Subject: How does your development environment look like?
Hi,
another question from an osgi beginner. How does your development
environment look like? I'm currently using eclipse and the maven bundle
plugin. My project is devided in several bundles / maven modules. Now,
if I'm working on a bundle and want to test it, I have to run maven and
afterwards deploy the bundle to the osgi framework, which could be done
by hand or by running a file monitoring bundle like "File install". But
this is not comfortable enough for me. I want to hit _one_ button in
eclipse and everything should be done as fast as possible. How do I
achieve that, is there a way?
Regards
Henrik
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org
Re: How does your development environment look like?
Posted by Henrik Niehaus <he...@gmx.de>.
Filippo Diotalevi schrieb:
> On Fri, Aug 14, 2009 at 6:45 PM, Henrik Niehaus<he...@gmx.de> wrote:
>> another question from an osgi beginner. How does your development
>> environment look like? I'm currently using eclipse and the maven bundle
>> plugin. My project is devided in several bundles / maven modules. Now,
>> if I'm working on a bundle and want to test it, I have to run maven and
>> afterwards deploy the bundle to the osgi framework, which could be done
>> by hand or by running a file monitoring bundle like "File install". But
>> this is not comfortable enough for me. I want to hit _one_ button in
>> eclipse and everything should be done as fast as possible. How do I
>> achieve that, is there a way?
>
> My development environment is very much similar to your.
> I use only Eclipse and Maven, and my project is divided in many maven
> modules/bundles.
>
> One of these modules is the main project that use Fileinstall to load
> bundles from a specified folder.
>
> When I update a single bundle, I just use a simple maven plugin I
> wrote to copy it in the folder watched by Fileinstall, so that the new
> bundle is hot deployed in the running application (you don't really
> need a mojo for that, a simple "cp" would work anyway).
>
>
Thanks Filippo,
that's exactly, what I'm doing now: mvn package && cp ...
I will check the other suggestions, too. But it looks like, this is as
good as it gets.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org
Re: How does your development environment look like?
Posted by Filippo Diotalevi <fi...@gmail.com>.
On Fri, Aug 14, 2009 at 6:45 PM, Henrik Niehaus<he...@gmx.de> wrote:
> another question from an osgi beginner. How does your development
> environment look like? I'm currently using eclipse and the maven bundle
> plugin. My project is devided in several bundles / maven modules. Now,
> if I'm working on a bundle and want to test it, I have to run maven and
> afterwards deploy the bundle to the osgi framework, which could be done
> by hand or by running a file monitoring bundle like "File install". But
> this is not comfortable enough for me. I want to hit _one_ button in
> eclipse and everything should be done as fast as possible. How do I
> achieve that, is there a way?
My development environment is very much similar to your.
I use only Eclipse and Maven, and my project is divided in many maven
modules/bundles.
One of these modules is the main project that use Fileinstall to load
bundles from a specified folder.
When I update a single bundle, I just use a simple maven plugin I
wrote to copy it in the folder watched by Fileinstall, so that the new
bundle is hot deployed in the running application (you don't really
need a mojo for that, a simple "cp" would work anyway).
--
Filippo Diotalevi
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org
Re: How does your development environment look like?
Posted by cr...@habuma.com.
As for me, my dev environment looks like this (although, I'm constantly
tweeking it):
- I'm using Eclipse (SpringSource ToolSuite, more specifically, but I'm
not yet actually using any of STS' OSGi/DM features).
- Pax Exam: This (via Pax Runner) lets me run my bundle project as a
whole just by typing 'pax-provision'. An OSGi runtime is started and all
of my project's bundles are deployed and ready for me to kick the tires.
- For more precise tests with minimal human involvement, I use Pax Exam
to run bundle integration tests against my bundles. Pax Exam tests can be
run anywhere you can run JUnit tests.
None of this is a "one button in Eclipse" solution (although, I suppose
running a Pax Exam test could be a one-click activity). But it's the
approach I favor at the moment.
> Hi,
>
> another question from an osgi beginner. How does your development
> environment look like? I'm currently using eclipse and the maven bundle
> plugin. My project is devided in several bundles / maven modules. Now,
> if I'm working on a bundle and want to test it, I have to run maven and
> afterwards deploy the bundle to the osgi framework, which could be done
> by hand or by running a file monitoring bundle like "File install". But
> this is not comfortable enough for me. I want to hit _one_ button in
> eclipse and everything should be done as fast as possible. How do I
> achieve that, is there a way?
>
> Regards
> Henrik
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org
How does your development environment look like?
Posted by Henrik Niehaus <he...@gmx.de>.
Hi,
another question from an osgi beginner. How does your development
environment look like? I'm currently using eclipse and the maven bundle
plugin. My project is devided in several bundles / maven modules. Now,
if I'm working on a bundle and want to test it, I have to run maven and
afterwards deploy the bundle to the osgi framework, which could be done
by hand or by running a file monitoring bundle like "File install". But
this is not comfortable enough for me. I want to hit _one_ button in
eclipse and everything should be done as fast as possible. How do I
achieve that, is there a way?
Regards
Henrik
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org
Re: Using OBR in host application
Posted by "Richard S. Hall" <he...@ungoverned.org>.
Did you read about embedding Felix in here:
http://felix.apache.org/site/apache-felix-framework-launching-and-embedding.html
It talks about this very issue in "Using Services Provided by Bundles"...
-> richard
On 8/14/09 11:28, Henrik Niehaus wrote:
> Hi Felix users,
>
> I'm trying to use the OBR service in an application, which embeds felix.
> This is what I'm doing:
>
> 1. Start the framework in the host application:
> private void startOsgiFramework() {
> // Create a case-insensitive configuration property map.
> Map<String, Object> configMap = new HashMap<String, Object>();
> // Add the bundle provided service interface package and the
> core OSGi
> // packages to be exported from the class path via the system
> bundle.
> configMap.put(BundleCache.CACHE_ROOTDIR_PROP, "cache");
> configMap.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA,
> "net.sf.jmp3renamer," +
> "net.sf.jmp3renamer.gui," +
> "net.sf.jmp3renamer.util," +
> "net.sf.jmp3renamer.plugins," +
> "net.sf.jmp3renamer.gui.components.historycombobox," +
> "org.slf4j;version=\"1.5\"");
>
> // add the mandatory bundles
> StringBuffer sb = new StringBuffer();
> File[] bundles = new File("../../bundle").listFiles();
> for (int i = 0; i< bundles.length; i++) {
> File bundle = bundles[i];
> sb.append("file:").append(bundle.getAbsolutePath()).append(' ');
> }
> String autoStart = sb.toString();
> logger.debug("Auto start packages: {}", autoStart);
> configMap.put(AutoActivator.AUTO_START_PROP + ".1", autoStart);
> configMap.put(FelixConstants.LOG_LEVEL_PROP, "3");
>
> // Create list to hold custom framework activators.
> List<BundleActivator> list = new ArrayList<BundleActivator>();
> // Add activator to process auto-start/install properties.
> list.add(new AutoActivator(configMap));
> list.add(this);
> // Add activators to the configuration map.
> configMap.put(FelixConstants.SYSTEMBUNDLE_ACTIVATORS_PROP, list);
>
> try {
> // Now create an instance of the framework with
> // our configuration properties and activator.
> m_felix = new Felix(configMap);
>
> // Now start Felix instance.
> m_felix.start();
>
> m_felix.getBundleContext();
>
> filePluginTracker = new FilePluginTracker(bndCtx,
> FilePlugin.class.getName(), null);
> filePluginTracker.open();
>
> dataPluginTracker = new DataPluginTracker(bndCtx,
> DataPlugin.class.getName(), null);
> dataPluginTracker.open();
>
> generalPluginTracker = new GeneralPluginTracker(bndCtx,
> GeneralPlugin.class.getName(), null);
> generalPluginTracker.open();
> } catch (Exception ex) {
> logger.error("Could not start osgi framework", ex);
> System.exit(1);
> }
> }
>
> 2. Try to get the OBR service:
> BundleContext ctx = Main.getBundleContext();
> ServiceReference sr =
> ctx.getServiceReference(RepositoryAdmin.class.getName());
> RepositoryAdmin adm = (RepositoryAdmin) ctx.getService(sr);
>
>
> I'm getting a ClassCastException, when I try to get the service from the
> bundle context:
> java.lang.ClassCastException:
> org.apache.felix.bundlerepository.RepositoryAdminImpl cannot be cast to
> org.osgi.service.obr.RepositoryAdmin.
> This sounds reasonable to me, because the interface class
> (RepositoryAdmin) gets loaded by the application's loader and the
> RepositoryAdminImpl comes from the obr bundle loader, which has also
> loaded the interface. So there are two "versions" of the interface and
> the cast doesn't work.
> But what can I do in such a situation? What's best practice for using
> bundle services in the host application?
>
> Regards
> Henrik
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
> For additional commands, e-mail: users-help@felix.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@felix.apache.org
For additional commands, e-mail: users-help@felix.apache.org