You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 13 Next »

A key part of a productive development environment is the tooling, for Apache ServiceMix the tooling is provided in the form of a powerful and flexible Apache Maven plugin.  The plugin has many useful features to enable you to work with the different project types available in JBI - such as Components, Service Assemblies, Service Units and Shared Librarys - and also allows you to work interact with a running Apache ServiceMix server by exposing the JSR-208 Ant Tasks as plugin goals.

Getting Started

In order to get started with the plugin you need to make it avilable to your project,  this is done by adding the following to your pom.xml.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  ...    <pluginRepositories>
    <pluginRepository>
      <id>apache.snapshots</id>
      <name>Maven Central Plugins Development Repository</name>
      <url>http://cvs.apache.org/maven-snapshot-repository</url>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
      <releases>
         <enabled>false</enabled>
      </releases>
    </pluginRepository>
  </pluginRepositories>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.servicemix.tooling</groupId>
        <artifactId>jbi-maven-plugin</artifactId>
        <extensions>true</extensions>
      </plugin>
    </plugins>
  </build>
</project>

Once this plugin has been added to your POM you can start using the capabilities.  In order to understand all the things you can do we have broken downs its functionality by the type of artifact you wish to create.  JBI covers the creation of four different types of artifact these are:

Binding Components/Service Engines 

These artifacts are the installers for components,  allowing you to register a Component that can either start and operate immediately or can wait for the deployment of a service unit.

Shared Libraries 

These are bundles of code or JAR's that you can install onto a server (with a given version) to allow components (BC/SE's) to share physical code.

Service Units 

These are zip archives created to contain configuration information of an instance of a service unit that can be deployed to a component (BC/SE)

Service Assembly 

A service assembly is a collection service units that can be deployed together,  it creates a zip archive containing each of the service units (SU's) 

Building and Installing Shared Libraries

The best place to start with the tooling is with the logically lowest component in the JBI spec,  which I suppose would be the Shared Library.  In essence a shared library is basically a JAR contains a set of JARs and a JBI.xml,  the important bits about the Shared Library is that it is named and versioned.  This fits nicely with the Maven approach since all maven artifacts have id's and versions,  and also the dependencies within your shared library POM can quickly be used to allow the JBI tooling to create the Shared Libraries zip archive.

In order to convert a standard project to a shared library you simply need to change the packaging (note you will need to have added the plugin repository and plugin from Getting Started).

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.apache.servicemix</groupId>
  <artifactId>MySharedLibrary</artifactId>
  <packaging>jbi-shared-library</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>A custom project</name>
  ...
</project>

Once you have set the packaging to be jbi-shared-library you can run mvn install and you will create both the standard jar packaging which will be set to your repository and also a ZIP packaging which will incorporate your dependencies and also a jbi.xml.

6/23/06 2:47:24 PM EDT: [INFO] ----------------------------------------------------------------------------
6/23/06 2:47:24 PM EDT: [INFO] Building A custom project
6/23/06 2:47:24 PM EDT: [INFO]    task-segment: [install]
6/23/06 2:47:24 PM EDT: [INFO] ----------------------------------------------------------------------------
6/23/06 2:47:24 PM EDT: [INFO] artifact org.apache.maven.plugins:maven-resources-plugin: checking for updates from central
6/23/06 2:47:25 PM EDT: [INFO] artifact org.apache.maven.plugins:maven-compiler-plugin: checking for updates from central
6/23/06 2:47:26 PM EDT: [INFO] artifact org.apache.maven.plugins:maven-surefire-plugin: checking for updates from central
6/23/06 2:47:27 PM EDT: [INFO] artifact org.apache.maven.plugins:maven-jar-plugin: checking for updates from central
6/23/06 2:47:27 PM EDT: [INFO] artifact org.apache.maven.plugins:maven-install-plugin: checking for updates from central
6/23/06 2:47:30 PM EDT: jbi:generate-jbi-shared-library-descriptor
6/23/06 2:47:30 PM EDT: [INFO] Generating jbi.xml
6/23/06 2:47:30 PM EDT: resources:resources
6/23/06 2:47:30 PM EDT: [INFO] Using default encoding to copy filtered resources.
6/23/06 2:47:31 PM EDT: compiler:compile
6/23/06 2:47:31 PM EDT: [INFO] Nothing to compile - all classes are up to date
6/23/06 2:47:31 PM EDT: resources:testResources
6/23/06 2:47:31 PM EDT: [INFO] Using default encoding to copy filtered resources.
6/23/06 2:47:31 PM EDT: compiler:testCompile
6/23/06 2:47:31 PM EDT: [INFO] No sources to compile
6/23/06 2:47:32 PM EDT: surefire:test
6/23/06 2:47:32 PM EDT: [INFO] No tests to run.
6/23/06 2:47:32 PM EDT: jar:jar
6/23/06 2:47:32 PM EDT: [INFO] Building jar: C:\Workspaces\runtime-New_configuration\MySharedLibrary\target\MySharedLibrary-1.0-SNAPSHOT.jar
6/23/06 2:47:32 PM EDT: jbi:jbi-shared-library
6/23/06 2:47:32 PM EDT: [INFO] Generating shared library C:\Workspaces\runtime-New_configuration\MySharedLibrary\target\MySharedLibrary-1.0-SNAPSHOT.zip
6/23/06 2:47:32 PM EDT: [INFO] Building jar: C:\Workspaces\runtime-New_configuration\MySharedLibrary\target\MySharedLibrary-1.0-SNAPSHOT.zip
6/23/06 2:47:32 PM EDT: install:install
6/23/06 2:47:32 PM EDT: [INFO] Installing C:\Workspaces\runtime-New_configuration\MySharedLibrary\target\MySharedLibrary-1.0-SNAPSHOT.jar to C:\Documents and Settings\pdodds\.m2\repository\org\apache\servicemix\MySharedLibrary\1.0-SNAPSHOT\MySharedLibrary-1.0-SNAPSHOT.jar
6/23/06 2:47:32 PM EDT: [INFO] Installing C:\Workspaces\runtime-New_configuration\MySharedLibrary\target\MySharedLibrary-1.0-SNAPSHOT.zip to C:\Documents and Settings\pdodds\.m2\repository\org\apache\servicemix\MySharedLibrary\1.0-SNAPSHOT\MySharedLibrary-1.0-SNAPSHOT.zip
6/23/06 2:47:32 PM EDT: BUILD SUCCESSFUL

The jbi.xml that was generated will provide for both the Java classes in this project and those in the dependencies to be made available and the shared library name and version will match the Maven pom.xml.

If you have a locally running Apache ServiceMix instance (which its default settings) you can even use the plugin to install the Shared Library by simply typing:

mvn jbi:installSharedLibrary

This will call the ANT tasks from within Maven giving the shared library to install as the one built in the install phase.

Building and Installing Components

JBI logically separates Binding Components and Service Engines as two flavours of a component, the Maven JBI tooling provides that you can define a project as a jbi-component and then specify whether it is a service-engine or binding-component. Like the shared libraries we have just covered the definition of a jbi-component firstly requires the steps from Getting Started (plugin repositories and plugin) and then it also requires you change the packaging of your project.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.apache.servicemix</groupId>
  <artifactId>MyBindingComponent</artifactId>
  <packaging>jbi-component</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>An example binding component</name>
  ...
</project>

Since a binding component or service engine has more settings than can be derived from your Maven POM.xml we also need to update the plugin section we added to configure these additional settings:

<plugin>
  <groupId>org.apache.servicemix.tooling</groupId>
  <artifactId>jbi-maven-plugin</artifactId>
  <extensions>true</extensions>
  <configuration>
    <type>binding-component</type>
    <bootstrap>org.apache.servicemix.MyBootstrap</bootstrap>
    <component>org.apache.servicemix.MyComponent</component>
  </configuration>
</plugin>

The parameters allow you to specify the following :

type - whether this is a binding-component or a service-engine
bootstrap - the name of the class that will be your bootstrap implementation
component - the name of the class that will be your component implementation

Once you have configured these steps you can run mvn install and much like the shared library maven will create both a standard jar and also a component installer:

Maven Log - Missing

If you have a locally running Apache ServiceMix instance (which its default settings) you can even use the plugin to install the Component by simply typing:

mvn jbi:installComponent

This will call the ANT tasks from within Maven giving the component to install as the one built in the install phase.

Maven 1.x Support 

Information on the Maven 1.x JBI plugin is available here.

  • No labels