Getting started with ServiceMix 4.2 and WebServices (with Maven and Eclipse on Windows)

(Under this post I noted down some great resources for getting started, so if you’re searching for those, have a look at the bottom of this article)

Okay, I had a really hard time getting started with ServiceMix, as there’re so many technologies involved and I knew none of them. Maven. OSGi. ServiceMix. Karaf. Most of the time, you only want something to work so you can apply the same or nearly the same technique again, right? So here’s a little plan what works and where you can start your journey:

- Install maven. Install Eclipse.

- Install the m2 plugin for eclipse.

- Download ServiceMix 4.2.

- Open a windows command terminal. Navigate to %servicemix_home%/bin

- “servicemix.bat” starts ServiceMix. You get into the Karaf console. Typing TAB and “y” shows you a lot of commands you can try out. (If you want, try some … easy administration!)

- Open Eclipse. Seriously. Import –> Maven project

- In the wizard, browse to %servicemix_home%/examples

- Pick the “cfx-osgi” folder and use the pom.xml the wizard finds there for importing the project. Finish the wizard.

- Change the sourcecode of the HelloWorldImpl.java file to do what you want and save that file.

- Right click the project –> Run –> Maven install. A .jar file gets generated.

- Copy that jar file into the %servicemix_home%/deploy folder.

- Get back to Eclipse … there’s a client.html file in the imported project. Right click that –> Open With –> Web Browser

- Click the “send” button. Smile.

- (Optional: Now remove the .jar file from the deploy folder of servicemix. Click the “send” button on the HTML form again. Smile.)

If you want to learn more, you can look into the FUSE ServiceMix documentation (FUSE is documenting and selling support for ServiceMix, but they don’t put much more on top of ServiceMix, so the documentation is pretty good). Or try the text files that come with the examples.

Hope this helped you a bit.

Edits and Updates:

  • I found this tutorial VERY helpful dealing with and understanding BCs: http://servicemix.apache.org/hello-world-bc.html
  • And as you will be using Spring anyways and there’s no way around it, just to understand how simple it works, begin with this small tutorial: Getting started with Spring
  • FUSE is a trademark that’s selling support for servicemix and label servicemix as “FUSE”. No matter if I got that right, FUSE is basically just ServiceMix. As the FUSE people are apt writing nice documentation (and the ServiceMix-page documentation basically sucks), you should head over to FUSE and read their docs (click on documentation and see a lot of nice PDFs). They explain everything you need in a well-written way – OSGi, Spring, Karaf, Maven, CXF, …
  • If you want to use Eclispe and Maven to build OSGi bundles, read this page calmly. It explains how you configure all the OSGi stuff in the pom.xml. Additionally, don’t try to use Eclipse’s plugin-development features as this will mess with your dependency resolution. Maven seems to say: put everything into my hands and you’ll be fine (even if you don’t like me).
  • This is a neat wiki article for getting started with building OSGi bundles for ServiceMix from Eclipse.
  • Here’s a nice article and tutorial explaining how to develop OSGi Bundles with Eclipse.

Related Posts:

13,717 Views, Posted Monday, August 23rd, 2010 under Programming.

19 comments

  1. As succinct as your post : Thanks !

    While we’re at it, i’m wondering if the fusesource bundle is woth it or just plain ServiceMix … Any thoughts ?

  2. I’m not using the FuseSource bundle, but the usual ServiceMix 4.2. But I guess the FuseSource bundle won’t perform worse.

  3. dead_devil_66 says:

    Hi! Thanks for the tutorial. :)

    I’m having a problem. When i press “send”, after opening the html within eclipse, i get an error saying “error opening”. If i press “send” with the html opened in my browser, the text box in the right is filled with “STATUS: 0″

    What’s wrong???

    Thanks

  4. dead_devil_66 says:

    i skipped a step in the process. Still, now i have cxf-osgi-4.2.0.jar and i copied it to deploy directory. Same error as before…

  5. There could be all kinds of problems, ServiceMix not running properly, Maven not setup correctly, wrong versions of .jars … sorry,man, but that’s not a problem I can debug without sitting on your system.

    Copying the cxf-osgi.jar into the deploy directory is usually not necessary. Did you import the example into eclipse and did the maven –> install? And then copy that file into the deploy folder? In other words: did you do what is written above?

  6. dead_devil_66 says:

    so, let me show you all the process :)

    importing the project:

    http://g.imagehost.org/0074/1_2.png

    http://j.imagehost.org/0661/2_9.png

    this is the file tree i get, in eclipse:

    http://g.imagehost.org/0245/3_9.png

    so, after selecting “Maven install”, i get this output in the console:

    [INFO] Scanning for projects…
    [WARNING]
    [WARNING] Some problems were encountered while building the effective model for

    org.apache.servicemix.examples:cxf-osgi:bundle:4.2.0
    [WARNING] ‘build.pluginManagement.plugins.plugin.(groupId:artifactId)’ must be

    unique but found duplicate declaration of plugin org.apache.maven.plugins:maven-

    surefire-plugin @ org.apache.servicemix.features:features:4.2.0, C:\Users

    \dead_devil_66\.m2\repository\org\apache\servicemix\features\features

    \4.2.0\features-4.2.0.pom, line 685, column 23
    [WARNING] ‘build.plugins.plugin.version’ for org.codehaus.mojo:exec-maven-plugin

    is missing. @ line 79, column 21
    [WARNING] The expression ${pom.artifactId} is deprecated. Please use

    ${project.artifactId} instead.
    [WARNING] ‘repositories.repository.layout’ for java.net uses the unsupported

    value ‘legacy’, artifact resolution might fail. @

    org.apache.servicemix.features:features:4.2.0, C:\Users

    \dead_devil_66\.m2\repository\org\apache\servicemix\features\features

    \4.2.0\features-4.2.0.pom, line 319, column 19
    [WARNING]
    [WARNING] It is highly recommended to fix these problems because they threaten

    the stability of your build.
    [WARNING]
    [WARNING] For this reason, future Maven versions might no longer support building

    such malformed projects.
    [WARNING]
    [INFO]
    [INFO] ————————————————————————
    [INFO] Building Apache ServiceMix Example :: CXF OSGi 4.2.0
    [INFO] ————————————————————————
    Downloading: http://repository.apache.org/content/groups/snapshots-

    group/org/codehaus/mojo/exec-maven-plugin/maven-metadata.xml
    [INFO]
    [INFO] — maven-dependency-plugin:2.1:copy (copy-legal) @ cxf-osgi —
    [INFO] Configured Artifact: org.apache.servicemix.legal:legal:1.0:xml
    [INFO] Copying legal-1.0.xml to C:\Users\dead_devil_66\Documents\apache-

    servicemix-4.2.0\examples\cxf-osgi\target\legal\legal.xml
    [INFO]
    [INFO] — maven-remote-resources-plugin:1.1:process (default) @ cxf-osgi —
    [INFO] Setting property: classpath.resource.loader.class =>

    ‘org.codehaus.plexus.velocity.ContextClassLoaderResourceLoader’.
    [INFO] Setting property: velocimacro.messages.on => ‘false’.
    [INFO] Setting property: resource.loader => ‘classpath’.
    [INFO] Setting property: resource.manager.logwhenfound => ‘false’.
    [INFO]
    [INFO] — maven-resources-plugin:2.3:resources (default-resources) @ cxf-osgi


    [INFO] Using ‘UTF-8′ encoding to copy filtered resources.
    [INFO] Copying 2 resources
    [INFO] Copying 3 resources
    [INFO]
    [INFO] — maven-compiler-plugin:2.0.2:compile (default-compile) @ cxf-osgi —
    [INFO] Compiling 3 source files to C:\Users\dead_devil_66\Documents\apache-

    servicemix-4.2.0\examples\cxf-osgi\target\classes
    [INFO]
    [INFO] — maven-resources-plugin:2.3:testResources (default-testResources) @

    cxf-osgi —
    [INFO] Using ‘UTF-8′ encoding to copy filtered resources.
    [INFO] skip non existing resourceDirectory C:\Users\dead_devil_66\Documents

    \apache-servicemix-4.2.0\examples\cxf-osgi\src\test\resources
    [INFO] Copying 3 resources
    [INFO]
    [INFO] — maven-compiler-plugin:2.0.2:testCompile (default-testCompile) @ cxf-

    osgi —
    [INFO] No sources to compile
    [INFO]
    [INFO] — maven-surefire-plugin:2.3.1:test (default-test) @ cxf-osgi —
    [INFO] Surefire report directory: C:\Users\dead_devil_66\Documents\apache-

    servicemix-4.2.0\examples\cxf-osgi\target\surefire-reports

    ——————————————————-
    T E S T S
    ——————————————————-
    There are no tests to run.

    Results :

    Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

    [INFO]
    [INFO] — maven-bundle-plugin:2.0.1:bundle (default-bundle) @ cxf-osgi —
    [INFO]
    [INFO] — maven-install-plugin:2.2:install (default-install) @ cxf-osgi —
    [INFO] Installing C:\Users\dead_devil_66\Documents\apache-servicemix-

    4.2.0\examples\cxf-osgi\target\cxf-osgi-4.2.0.jar to C:\Users

    \dead_devil_66\.m2\repository\org\apache\servicemix\examples\cxf-osgi\4.2.0\cxf-

    osgi-4.2.0.jar
    [INFO] Installing C:\Users\dead_devil_66\Documents\apache-servicemix-

    4.2.0\examples\cxf-osgi\pom.xml to C:\Users\dead_devil_66\.m2\repository\org

    \apache\servicemix\examples\cxf-osgi\4.2.0\cxf-osgi-4.2.0.pom
    [INFO]
    [INFO] — maven-bundle-plugin:2.0.1:install (default-install) @ cxf-osgi —
    [INFO] Parsing file:/C:/Users/dead_devil_66/.m2/repository/repository.xml
    [INFO] Installing org/apache/servicemix/examples/cxf-osgi/4.2.0/cxf-osgi-

    4.2.0.jar
    [INFO] Writing OBR metadata
    [INFO] ————————————————————————
    [INFO] BUILD SUCCESS
    [INFO] ————————————————————————
    [INFO] Total time: 19.019s
    [INFO] Finished at: Wed Jan 19 18:30:45 GMT 2011
    [INFO] Final Memory: 11M/28M
    [INFO] ————————————————————————

    a pic of the location of the jar and the deploy dir, after copying the jar:

    http://j.imagehost.org/0571/4_8.png

    http://j.imagehost.org/0915/5.png

    and this is the final result…..

    http://j.imagehost.org/0066/7_20.png

  7. dead_devil_66 says:

    oh, and this is the option i selected to generate the jar:

    http://j.imagehost.org/0820/8_2.png

    i selected the option 8…

  8. If you started service mix and did what was written above in the correct sequence, than it should work.

  9. dead_devil_66 says:

    in this link,

    http://hydrogen.informatik.tu-cottbus.de/wiki/index.php/Apache_ServiceMix_4.0_/_interconnect_OSGi_bundles

    when creating a jar, seems that i need to run a command to install the module. Did you forget that???

  10. No .jars that you drop into the deploy folder get automatically installed. After you have installed the .jar in your maven repository, you must either install it in servicemix via a command in Karaf or you have to copy the .jar from your Maven Repository (under users/yourname/.m2/repository/… ) into the deploy folder. I didn’t mention the path in the post above, maybe that’s what was misleading.

    If that doesn’t work, please take a look into the servicemix/examples/cfx-osgi folder. There’s a readme.txt or something similar in it. Make sure that this example works for you first – otherwise some part might be broken.

    Trying out the maven eclipse plugin today I saw that it was broken by a recent update on my machine … maybe you have the same problem if you get build failure when installing via maven.

  11. dead_devil_66 says:

    well, if i follow the example in the readme file, seems i can get the wsdl.

    Thanks for the help :)

  12. Hey Tim,
    Sorry to abuse this comments thread but i have a little question :
    Which example on servicemix do you thing is nearest to this scenario :
    A remote web service (i have its wsdl) that i’d like to “proxy” on servicemix, or use into some kind of camel route ?

  13. thanks for your tutorial… :D

  14. very helpful… thanks

  15. sracem says:

    Hi,

    Thanks for this tutorial :)

    in fact i want to run SMX 4.2 under jbossAs 5, what you assume: deploy servicemix as JBI components or OSGI bundles. and how i can do this?

    thanks

  16. Themba says:

    Hi, thanks for this tutorial but i’m having a problem when import a project to eclipse workspace, the following error with the pom seems to persist. Please help

    Project build error: Non-resolvable parent POM for org.apache.servicemix.examples:examples:4.2.0-fuse-02-00: Failure to transfer org.apache.servicemix.features:features:pom:4.2.0-fuse-02-00 from http://repo.fusesource.com/maven2/ was cached in the local repository, resolution will not be reattempted until the update interval of fusesource.m2 has elapsed or updates are forced. Original error: Could not transfer artifact org.apache.servicemix.features:features:pom:4.2.0-fuse-02-00 from/to fusesource.m2 (http://repo.fusesource.com/maven2/): Connect times out and ‘parent.relativePath’ points at wrong local POM

  17. Hi Tim,
    Thank you for the article. This is a good start. I am able to import the files without issue but I am getting different error.

    org.apache.hello_world_soap_http.Greeter is missing in the project and maven dependencies is not able to resolve this.

    Did all the projects got resolved automatically for you.
    Is the maven lifecycle is not showing any conflict for you.

    Thank you for the help

  18. Thanks Tim for the Post.
    The folks reading the post, some of my comments may help.

    Servicemix 4.2 is based on JDK 6. Dont use JDK 7. you may face errors while starting the Servicemix

    M2E new version gives error about the lifecycle. go ignore the plugins then and update configurations.Lot of post shows adding the plugin management but the pom.xml has parents which makes it very difficult to introduce ignore goals. Put some time it will compile.

    You have to work on the project to correct the JRE library dependency.
    Rest follow the blog, and the readme text in the project.

Leave a Reply