Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Creating the Maven Projects for Each Component

Creating a Skeleton Project For the JBI Service Engine

...

The focus of this section is on the creation of a JBI component. For this task, a Maven archetype will be used to create a Maven project skeleton to house the component. Maven archetypes are templates for Maven projects that jumpstart project creation via the automation of repetitive tasks by following standard conventions. The result of using an archetype to create a Maven project is a directory structure, a Maven POM file and, depending on the archetype being used, sometimes Java objects and JUnit tests.

...

1) Create a directory named hello-world-se and switch to that directory:

Code Block
$ mkdir hello-world-smx
$ cd hello-world-sesmx

2) Use a the servicemix-service-engine Maven archetype to generate a Maven project for the SE:

Panel

$ mvn archetype:create -DarchetypeGroupId=org.apache.servicemix.tooling -DarchetypeArtifactId=servicemix-service-engine \
-DarchetypeVersion=3.1-incubating-SNAPSHOT -DgroupId=org.apache.servicemix.samples.helloworld -DartifactId=hello-world-se

The command above will create a directory named hello-world-se that houses a Maven project for the JBI service engine being created here.

The first three parameters to the mvn command (-DarchetypeGroupId=org.apache.servicemix.tooling -DarchetypeArtifactId=servicemix-service-engine -DarchetypeVersion=3.1-incubating-SNAPSHOT) identify which Maven archetype to use for the archetype:create goal, while the last two parameters (-DgroupId=org.apache.servicemix.samples.helloworld -DartifactId=hello-world-se) uniquely identify the Maven project that is being generated. The groupId (printed in pink) is used as the Java package and the artifactId is used as the project name. Therefore, only alphanumeric characters valid values for the groupId and artifactId parameters.

Tip

The value of the archetypeVersion parameter in the command above (3.1-incubating-SNAPSHOT) may need to be updated to the current ServiceMix version in order for the command to work correctly. The latest version can always be found in the top level ServiceMix POM in the <version> element.

The output from executing the archetype:create goal is shown below (only relevant information has been preserved):

Panel

Wiki Markup
\[INFO\] Scanning for projects...
\[INFO\] Searching repository for plugin with prefix: 'archetype'.
\[INFO\] \---------------------------------------------------------------------------\-
\[INFO\] Building Maven Default Project
\[INFO\]    task-segment: \[archetype:create\] (aggregator-style)
\[INFO\] \---------------------------------------------------------------------------\-
...
\[INFO\] <span style="color: #ff00ff">Defaulting package to group ID: org.apache.servicemix.samples.helloWorldSE</span>
...
\[INFO\] **\**\**\**\**\**\**\**\**\**\* End of debug info from resources from generated POM **\**\******************\*
\[INFO\] <span style="color: #009900">Archetype created in dir: C:\/Users/bsnyder/src/hello-world-SE-SU-SA\se/hello-world-SE<se</span>
\[INFO\] \-----------------------------------------------------------------------\-
\[INFO\] BUILD SUCCESSFUL
\[INFO\] \-----------------------------------------------------------------------\-

...

Note
titleIn case of a BUILD ERROR: Maven plugin version requirement

The maven-archetype-plugin 1.0-alpha4 or above is required for this tutorial. When an older version is installed, a build error will occur. The version of this plugin can be checked by verifying the name of the following directories:

Code Block
titleUnix
\~/.m2/repository/org/apache/maven/plugins/maven-archetype-plugin 
Code Block
titleWindows
C:\Documents and Settings\<USERNAME_>

In case the only version available is an older one, a minimal pom.xml file will need to be created manually in the hello-world-se directory:

Code Block
titleMinimal pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" 
         xmlnsxmlns: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>mygroup<<groupId>org.apache.servicemix.samples</groupId>
  <artifactId>myartifact<<artifactId>hello-world-se</artifactId>
  <version>myversion<<packaging>pom</version>packaging>
  <packaging>pom</packaging><version>1.0-SNAPSHOT</version>

  <build>
    <pluginManagement>
      <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-archetype-plugin</artifactId>
          <version>1.0-alpha-4</version>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>

Creating the Project For the

...

Service Unit and

...

Service Assembly

The archetypes for SUs and SAs do not contain much code, but rather help with tasks related to Maven. Later, we will only need to adapt the POMs to our project - just little work.

1) From within the directory hello-world-sesmx directory, execute the following commands to create the project for the SU:

Code Block
$ mvn archetype:create -DarchetypeGroupId=org.apache.servicemix.tooling -DarchetypeArtifactId=servicemix-service-unit \
-DarchetypeVersion=3.1-incubating-SNAPSHOT -DgroupId=org.apache.servicemix.samples.helloworld -DartifactId=hello-world-su

2) From within the directory hello-world-sesmx directory, execute the following commands to create the project for the SA:

Code Block
$ mvn archetype:create -DarchetypeGroupId=org.apache.servicemix.tooling -DarchetypeArtifactId=servicemix-service-assembly \
-DarchetypeVersion=3.1-incubating-SNAPSHOT -DgroupId=org.apache.servicemix.samples.helloworld -DartifactId=hello-world-sa

The directory structures for each project should appear as follows:

Code Block

C:\hello-world-se\hello-world-sa
C:\hello-world-se\hello-world-sa\pom.xml


C:\hello-world-se\hello-world-se
C:\hello-world-se\hello-world-se\pom.xml

C:\hello-world-se\hello-world-se\src\main\java\org\apache\servicemix\samples\helloworld
C:\hello-world-se\hello-world-se\src\main\java\org\apache\servicemix\samples\helloworld\MyBootstrap.java
C:\hello-world-se\hello-world-se\src\main\java\org\apache\servicemix\samples\helloworld\MyComponent.java
C:\hello-world-se\hello-world-se\src\main\java\org\apache\servicemix\samples\helloworld\MyDeployer.java
C:\hello-world-se\hello-world-se\src\main\java\org\apache\servicemix\samples\helloworld\MyEndpoint.java
C:\hello-world-se\hello-world-se\src\main\java\org\apache\servicemix\samples\helloworld\MyLifeCycle.java
C:\hello-world-se\hello-world-se\src\main\java\org\apache\servicemix\samples\helloworld\MySpringComponent.java

C:\hello-world-se\hello-world-se\src\test\java\org\apache\servicemix\samples\helloworld
C:\hello-world-se\hello-world-se\src\test\java\org\apache\servicemix\samples\helloworld\MySpringComponentTest.java

C:\hello-world-se\hello-world-se\src\test\resources
C:\hello-world-se\hello-world-se\src\test\resources\spring.xml


C:\hello-world-se\hello-world-su
C:\hello-world-se\hello-world-su\pom.xml
C:\hello-world-se\hello-world-su\src\main\resources

According to the template rules, all Java objects are prefixed with the word My. These Java objects can be renamed to whatever you prefer, making sure to also change the names in the corresponding resource files (all tests and {{pom.xml}}s) as well.

Incorporating the SU and SA Into the Top Level POM

Now that we have created the SU and SA projects, the top level pom.xml} must be made aware of each one. In the {{hello-world-se directory create a file named pom.xml containing the following content:

Code Block

<project>
  <modelVersion>4.0.0</modelVersion>

  <groupId>org.apache.servicemix.samples</groupId>
  <artifactId>hello-world-se</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>pom</packaging>

  <modules>
    <module>hello-world-sa</module>
    <module>hello-world-su</module>
  </modules>

  <dependencies>
    <dependency>
      <groupId>org.apache.servicemix.samples.helloWorldse</groupId>
      <artifactId>hello-world-su</artifactId>
      <version>1.0-SNAPSHOT</version>
    </dependency>
  </dependencies>

</project>

The <modules> element denotes the child projects that were created using the Maven archetypes and the <dependencies> element tells Maven to include the SU into the SA when it is constructed.

Note

The content of the <version> element is arbitrary and is used to describe not the version of ServiceMix but of the version of projects that were just created. We just have to use consistently the same version when we reference this project.

Using Maven to Build and Package the Components

By now, it is already possible to call Maven with the relevant goals.

Compiling the Components

In order to build, package and place a copy of each component in the Maven repository onyour local machine, execute the following from within hello-world-se directory:

Code Block

mvn install 

in the hello-world-SE-SU-SA/hello-world-SE directory and Maven shall present as one of the last lines of output

No Format

[INFO] BUILD SUCCESSFUL

Upon successful execution of the archetype:create goal, look for the BUILD SUCCESSFUL output. If instead you see the BUILD FAILED output, you'll need to look at the rest of the output to troubleshoot the issue. In case this success information does not appear, the output will provide some information about what might have gone awry. Assistance with any issue you might experience is available from the ServiceMix community via the ServiceMix mailing lists archive.

Incorporating the Service Unit and Service Assembly Into a Top Level POM

Now that we have created the SU and SA projects, a the top level pom.xml} must be manually created and made aware of each one. In the {{hello-world-se directory create a file named pom.xml containing the following content:

Code Block

<?xml version="1.0" encoding="UTF-8"?>
<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.samples</groupId>
  <artifactId>hello-world-se</artifactId>
  <packaging>pom</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>Hello World JBI Sample</name>

  <modules>
    <module>hello-world-sa</module>
    <module>hello-world-su</module>
  </modules>

  <dependencies>
    <dependency>
      <groupId>org.apache.servicemix.samples.helloworld</groupId>
      <artifactId>hello-world-su</artifactId>
      <version>1.0-SNAPSHOT</version>
    </dependency>
  </dependencies>

</project>

This POM will allow this example to be easily folded in to the ServiceMix samples. The <modules> element denotes the child projects that were created using the Maven archetypes and the <dependencies> element tells Maven to include the SU into the SA when it is constructed.

Give Each of the Component Projects a Name

When sitting in the hello-world-smx directory, you should now see the following:

No Format

hello-world-sa
hello-world-se
hello-world-su
pom.xml

Now we need to give each component's pom.xml an appropriate name. This name will allow Maven's output to denote a component's name in its output making our development work a bit easier. To name each project, simply edit each pom.xml and replace <name>A custom project</name> with an appropriate name. Below are the instructions for naming each component's project:

  • Edit hello-world-sa/pom.xml and change <name>a custom project</name> with <name>Hello World Service Assembly</name>
  • Edit hello-world-se/pom.xml and change <name>a custom project</name> with <name>Hello World Service Engine</name>
  • Edit hello-world-su/pom.xml and change <name>a custom project</name> with <name>Hello World Service Unit</name>

A Quick Look at the Directory Hierarchy

After executing the Maven archetypes above, you should now be able to see the following directory hierarchy:

No Format

./hello-world-sa
./hello-world-sa/pom.xml
./hello-world-se
./hello-world-se/pom.xml
./hello-world-se/src
./hello-world-se/src/main
./hello-world-se/src/main/java
./hello-world-se/src/main/java/org
./hello-world-se/src/main/java/org/apache
./hello-world-se/src/main/java/org/apache/servicemix
./hello-world-se/src/main/java/org/apache/servicemix/samples
./hello-world-se/src/main/java/org/apache/servicemix/samples/helloworld
./hello-world-se/src/main/java/org/apache/servicemix/samples/helloworld/MyBootstrap.java
./hello-world-se/src/main/java/org/apache/servicemix/samples/helloworld/MyComponent.java
./hello-world-se/src/main/java/org/apache/servicemix/samples/helloworld/MyEndpoint.java
./hello-world-se/src/test
./hello-world-se/src/test/java
./hello-world-se/src/test/java/org
./hello-world-se/src/test/java/org/apache
./hello-world-se/src/test/java/org/apache/servicemix
./hello-world-se/src/test/java/org/apache/servicemix/samples
./hello-world-se/src/test/java/org/apache/servicemix/samples/helloworld
./hello-world-se/src/test/java/org/apache/servicemix/samples/helloworld/MySpringComponentTest.java
./hello-world-se/src/test/resources
./hello-world-se/src/test/resources/log4j.properties
./hello-world-se/src/test/resources/spring.xml
./hello-world-su
./hello-world-su/pom.xml
./hello-world-su/src
./hello-world-su/src/main
./hello-world-su/src/main/resources
Tip
titleUnix

To show the entire directory hierarchy, simply execute find . from the command line

Tip
titleWindows

To show the entire directory hierarchy, simply execute find from the command line

According to the archetype rules, all Java objects are prefixed with the word My. The Java objects can be renamed to whatever you prefer, making sure to also change the names in the corresponding resource files (all tests and {{pom.xml}}s) as well.

Note

The content of the <version> element is arbitrary and is used to describe not the version of ServiceMix but of the version of projects that were just created. We just have to use consistently the same version when we reference this project.

How to Build and Package the Components

By now, it is already possible to call Maven with the relevant goals.

Compiling the Components

In order to, among other things, build and package the components, execute the following from within hello-world-smx directory:

Code Block

mvn install 
No Format

...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] ------------------------------------------------------------------------
[INFO] Hello World Service Assembly .......................... SUCCESS [11.583s]
[INFO] Hello World Service Unit .............................. SUCCESS [0.656s]
[INFO] Hello World JBI Sample ................................ SUCCESS [1.517s]
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 14 seconds
[INFO] Finished at: Fri Dec 01 00:35:06 MST 2006
[INFO] Final Memory: 13M/25M
[INFO] ------------------------------------------------------------------------

Upon successful execution of the install goal, look for the BUILD SUCCESSFUL output as shown above. In addition, because each pom.xml has been given a name, each project can be easily identified. If instead you see the BUILD FAILED output, you'll need to look at the rest of the output to troubleshoot the issue. In case this success information does not appear, the output will provide some information about what might have gone awry. Assistance with any issue you might experience is available from the ServiceMix community via the ServiceMix mailing lists archive.

...