To use ServiceMix my project has to be an OSGi bundle?
Asked Answered
C

3

5

I' starting to use ServiceMix and Camel and I've run through many examples.

It seems that the examples that are OSGi can be deployed in ServiceMix via hot deploy or via console, but I don't know how to deploy a project that is not an OSGI. Can it be done?

For example, I'm looking at the example project from Camel 2.10.0 called camel-example-cxf-proxy. I did some alterations and now I wanted to load it in ServiceMix. If I copy/paste to the deploy directory it is loaded but when I try to run it via osgi:start id it fails.

However if I run it from the IDE as a standalone it runs just fine and I can send and receive requests via SoapUI.

When I'm done with the examples I'll want to create my own project in eclipse and do tests in the IDE and in ServiceMix. I don't really understand the advantage of OSGi yet. SO I'm not too compelled to use OSGi for my project.

My main question is: Can I deploy a non-OSGi non-JBI compliant project in servicemix? Something like the camel-example-cxf-proxy. If yes, how can I do it? If no, how can I OSGi-fy the camel-example-cxf-proxy?

Thank you :)

Casanova answered 7/9, 2012 at 14:35 Comment(0)
S
5

Apache ServiceMix which uses Apache Karaf as its kernel, support pluggable deployment units. Though OSGi is the main unit.

You can deploy JBI artifacts (eg JBI was used as deployment units for Apache ServiceMix 3.x). So we offer that as a migration path to run JBI in SMX 4.x.

A plain WAR file can be deployed as well. You can for example just drop a .war file in the deploy directory. If you deploy from the shell, you need to prefix the deployer with war so it knows to use the war deployer.

There is some documentation about the various pluggable deployers here http://fusesource.com/docs/esbent/7.0/esb_deploy_osgi/UrlHandlers.html

For example to install an Apache Wicket WAR example using Maven you can do from the shell:

osgi:install war:mvn:org.apache.wicket/wicket-examples/1.4.7/war?Web-ContextPath=wicket

The Apache documentation about deployer is mainly documented at Apache Karaf http://karaf.apache.org/manual/2.2.9/users-guide/deployer.html

Now to deploy OSGi applications can be a bit of pain to assemble. And that is why FuseSource created FAB to make it much easier. I blogged about this a bit, which references to videos and more material: http://www.davsclaus.com/2012/08/osgi-deployment-made-easy-with-fab.html

With FAB you can just deploy regular Maven projects out of the box without any OSGi pain.

Sardonic answered 8/9, 2012 at 8:48 Comment(3)
Thanks for the info! I'm trying the FAB and the maven plugin to see if I can solve my problem. I'm trying to load the camel-example-cxf-proxy by copying the jar file produced with maven to the deploy directory but when I try to start the bundle I get this : "org.osgi.framework.BundleException: Unresolved constraint in bundle org.apache.camel.camel-example-cxf-proxy [259]: Unab le to resolve 259.0: missing requirement [259.0] package; (&(package=META-INF.cxf)(version>=2.6.0)(!(version>=3.0.0)))" I don't know how to correct this, but the bundle won't start.Casanova
Apache ServiceMix 4.4.x does not support Camel 2.10. It only supports Camel 2.8. ServiceMix 4.5 (still to be released) will support Camel 2.10 and ActiveMQ 5.7 (we need to release this first)Sardonic
Thank you for your answer Claus Ibsen, this helped a lot.Casanova
F
3

If your project is a maven project, you can try :

mvn install

Then start your servicemix, and in servicemix command line :

install mvn:groupId/artifactId/version

This will prompt a bundle ID. Then, juste start the bundle :

start <bundle_id>

You can check the state of your bundle with command "list"

Flip answered 7/9, 2012 at 14:50 Comment(3)
I tried this solution but I can't seem to start the bundle. It shows me the exception "org.osgi.framework.BundleException: Unresolved constraint in bundle org.apache.camel.camel-example-cxf-proxy [259]: Unab le to resolve 259.0: missing requirement [259.0] package; (&(package=META-INF.cxf)(version>=2.6.0)(!(version>=3.0.0)))"Casanova
It seems that either a configuration file is missing in META-INF or you are using a non-compatible versionFlip
Thank you for your answer, as it turns out I was using an unsupported combination: Camel 2.10 and ServiceMix 4.4.xCasanova
D
1

The project has to be a bundle to be installed in servicemix / karaf. So the steps to make a camel project work in OSGi are the following.

  1. Use the maven bundle plugin in the pom and configure it to import / export the necessary packages if necessary.

  2. Make sure your camel context is defined in a way that OSGi can start. This is either in the activator of the bundle or in a spring config in the right location or with a blueprint config in the right location.

See two of my karaf tutorials for the details:

CXF: http://www.liquid-reality.de/x/EoBk

Camel: http://www.liquid-reality.de/x/G4Bk

Decuple answered 8/9, 2012 at 12:57 Comment(2)
This is not true, you can deploy a WAR file, or use a wrap to deploy a non OSGi bundle (eg a plain JAR). However OSGi is the main deployment unit in SMX, and therefore most people use OSGi deployment model.Sardonic
Sure you can deploy a war or a plain jar. But I think explaining that confuses people more than it helps :-)Decuple

© 2022 - 2024 — McMap. All rights reserved.