이 콘텐츠는 선택한 언어로 제공되지 않습니다.

Chapter 15. OSGi Bundle Tutorials


Abstract

This chapter presents tutorials for Apache Camel and Apache CXF applications. Each tutorial describes how to generate, build, run, and deploy an application as an OSGi bundle.

15.1. Generating and Running an EIP Bundle

Overview

This section explains how to generate, build, and run a complete Apache Camel example as an OSGi bundle, where the starting point code is generated with the help of a Maven archetype.

Prerequisites

In order to generate a project using an Red Hat JBoss Fuse Maven archetype, you must have the following prerequisites:
  • Maven installation—Maven is a free, open source build tool from Apache. You can download the latest version from http://maven.apache.org/download.html (minimum is 2.0.9).
  • Internet connection—whilst performing a build, Maven dynamically searches external repositories and downloads the required artifacts on the fly. In order for this to work, your build machine must be connected to the Internet.
  • fusesource Maven repository is configured—in order to locate the archetypes, Maven's settings.xml file must be configured with the location of the fusesource Maven repository. For details of how to set this up, see the section called “Adding the Red Hat JBoss Fuse repository”.

Generating an EIP bundle

The servicemix-camel-osgi-bundle archetype creates a router project, which is configured to deploy as a bundle. To generate a Maven project with the coordinates, org.fusesource.example:camel-bundle, enter the following command:
mvn archetype:generate
-DarchetypeGroupId=org.apache.servicemix.tooling
-DarchetypeArtifactId=servicemix-camel-osgi-bundle
-DarchetypeVersion=2012.01.0.redhat-60024
-DgroupId=org.fusesource.example
-DartifactId=camel-bundle
Copy to Clipboard Toggle word wrap
The result of this command is a directory, ProjectDir/camel-bundle, containing the files for the generated bundle project.

Running the EIP bundle

To install and run the generated camel-bundle project, perform the following steps:
  1. Build the project—open a command prompt and change directory to ProjectDir/camel-bundle. Use Maven to build the demonstration by entering the following command:
    mvn install
    Copy to Clipboard Toggle word wrap
    If this command runs successfully, the ProjectDir/camel-bundle/target directory should contain the bundle file, camel-bundle-1.0-SNAPSHOT.jar and the bundle will also be installed in the local Maven repository.
  2. Install prerequisite features (optional)—by default, the camel-core feature and some related features are pre-installed in the OSGi container. But many of the Apache Camel components are not installed by default. To check which features are available and whether or not they are installed, enter the following console command:
    JBossFuse:karaf@root> features:list
    Copy to Clipboard Toggle word wrap
    Apache Camel features are identifiable by the camel- prefix. For example, if one of your routes requires the HTTP component, you can make sure that it is installed in the OSGi container by issuing the following console command:
    JBossFuse:karaf@root> features:install camel-http
    Copy to Clipboard Toggle word wrap
  3. Install and start the camel-bundle bundle—at the Red Hat JBoss Fuse console, enter the following command:
    JBossFuse:karaf@root> osgi:install -s file:ProjectDir/camel-bundle/target/camel-bundle-1.0-SNAPSHOT.jar
    Copy to Clipboard Toggle word wrap
    Where ProjectDir is the directory containing your Maven projects and the -s flag directs the container to start the bundle right away. For example, if your project directory is C:\Projects on a Windows machine, you would enter the following command:
    JBossFuse:karaf@root> osgi:install -s file:C:/Projects/camel-bundle/target/camel-bundle-1.0-SNAPSHOT.jar
    Copy to Clipboard Toggle word wrap
    Alternatively, you could install the bundle from the local Maven repository using an Mvn URL (see Section A.3, “Mvn URL Handler”) as follows:
    JBossFuse:karaf@root> osgi:install -s mvn:org.fusesource.example/camel-bundle
    Copy to Clipboard Toggle word wrap
    After entering this command, you should soon see output like the following being logged to the console screen:
    >>>> MyTransform set body:  Mon Sep 22 11:43:42 BST 2008
    >>>> MyTransform set body:  Mon Sep 22 11:43:44 BST 2008
    >>>> MyTransform set body:  Mon Sep 22 11:43:46 BST 2008
    Copy to Clipboard Toggle word wrap
    Note
    On Windows machines, be careful how you format the file URL—for details of the syntax understood by the file URL handler, see Section A.1, “File URL Handler”.
  4. Stop the camel-bundle bundle—to stop the camel-bundle bundle, you first need to discover the relevant bundle number. To find the bundle number, enter the following console command (this might look a bit confusing, because the text you are typing will intermingle with the output that is being logged to the screen):
    JBossFuse:karaf@root> osgi:list
    Copy to Clipboard Toggle word wrap
    At the end of the listing, you should see an entry like the following:
    [ 189] [Active     ] [            ] [       ] [   60] A Camel OSGi Service Unit (1.0.0.SNAPSHOT)
    Copy to Clipboard Toggle word wrap
    Where, in this example, the bundle number is 189. To stop this bundle, enter the following console command:
    JBossFuse:karaf@root> osgi:stop 189
    Copy to Clipboard Toggle word wrap
맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2025 Red Hat