...
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<samples.helloworld</groupId> <artifactId>hello-world-se<smx</artifactId> <packaging>pom</packaging> <version>1.0-SNAPSHOT</version> <name>Hello World JBI Sample<Component</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 the example to be easily folded in to the ServiceMix samples. The <modules>
element denotes the subprojects other 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 Maven Subprojects a Name
When sitting in the . Once the pom.xml
file from above is saved into the hello-world-smx
directory, you should now see the following:
No Formatcode |
---|
$ ls 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 replace<name>a custom project</name>
with<name>Hello World Service Assembly</name>
- Edit
hello-world-se/pom.xml
and replace<name>a custom project</name>
with<name>Hello World Service Engine</name>
- Edit
hello-world-su/pom.xml
and replace<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 | ||
---|---|---|
| ||
To show the entire directory hierarchy, simply execute |
Tip | ||
---|---|---|
| ||
To show the entire directory hierarchy, simply execute |
According to the archetype rules, all Java objects generated from the archetype:create
goal 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 and all tests and {{pom.xml}}s) as well.
Note |
---|
The content of the |
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 command from within hello-world-smx
directory:
Code Block |
---|
mvn install
|
All projects can now be built using the following command on the command-line:
Code Block |
---|
$ mvn clean install
|
The command above should display the output below:
No Format |
---|
[INFO] Scanning for projects...
[INFO] Reactor build order:
[INFO] A custom project
[INFO] A custom project
[INFO] Hello World JBI Component
[INFO] ----------------------------------------------------------------------------
[INFO] Building A custom project
[INFO] task-segment: [clean, install]
[INFO] ----------------------------------------------------------------------------
[INFO] [clean:clean]
[INFO] Deleting directory /Users/bsnyder/src/hello-world-smx/hello-world-su/target
[INFO] Deleting directory /Users/bsnyder/src/hello-world-smx/hello-world-su/target/classes
[INFO] Deleting directory /Users/bsnyder/src/hello-world-smx/hello-world-su/target/test-classes
[INFO] [xbean:mapping {execution: default}]
Checking: org.apache.servicemix.samples.helloworld.MyComponent
Checking: org.apache.servicemix.samples.helloworld.MyEndpoint
[INFO] Generating META-INF properties file: /Users/bsnyder/src/hello-world-smx/hello-world-su/target/xbean/META-INF/services/org/apache/xbean/spring/http/
org.apache.servicemix.samples.helloworld/1.0 for namespace: http://org.apache.servicemix.samples.helloworld/1.0
[INFO] Generating Spring 2.0 handler mapping: /Users/bsnyder/src/hello-world-smx/hello-world-su/target/xbean/META-INF/spring.handlers
for namespace: http://org.apache.servicemix.samples.helloworld/1.0
[INFO] Generating Spring 2.0 schema mapping: /Users/bsnyder/src/hello-world-smx/hello-world-su/target/xbean/META-INF/spring.schemas
for namespace: http://org.apache.servicemix.samples.helloworld/1.0
[INFO] Generating HTML documentation file: /Users/bsnyder/src/hello-world-smx/hello-world-su/target/xbean/hello-world-su.xsd.html
for namespace: http://org.apache.servicemix.samples.helloworld/1.0
[INFO] Generating XSD file: /Users/bsnyder/src/hello-world-smx/hello-world-su/target/xbean/hello-world-su.xsd
for namespace: http://org.apache.servicemix.samples.helloworld/1.0
[INFO] Generating WIKI documentation file: /Users/bsnyder/src/hello-world-smx/hello-world-su/target/xbean/hello-world-su.xsd.wiki
for namespace: http://org.apache.servicemix.samples.helloworld/1.0
Warning, could not load class: org.apache.servicemix.samples.helloworld.MyEndpoint
[INFO] ...done.
Downloading: http://repo.mergere.com/maven2/xml-security/xmlsec/1.3.0/xmlsec-1.3.0.pom
[WARNING] Unable to get resource from repository central (http://repo1.maven.org/maven2)
Downloading: http://repo.mergere.com/maven2/wss4j/wss4j/1.5.0/wss4j-1.5.0.pom
[WARNING] Unable to get resource from repository central (http://repo1.maven.org/maven2)
[INFO] [jbi:generate-jbi-component-descriptor]
[INFO] Generating jbi.xml
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:compile]
Compiling 3 source files to /Users/bsnyder/src/hello-world-smx/hello-world-su/target/classes
[INFO] [resources:testResources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:testCompile]
Compiling 1 source file to /Users/bsnyder/src/hello-world-smx/hello-world-su/target/test-classes
[INFO] [surefire:test]
[INFO] Surefire report directory: /Users/bsnyder/src/hello-world-smx/hello-world-su/target/surefire-reports
-------------------------------------------------------
T E S T S
----------------------------------- |
No Format |
... [INFO] -------------------- Running org.apache.servicemix.samples.helloworld.MySpringComponentTest <hello>Hello World! Message [<hello>Ski Colorado!</hello>] contains [28] bytes</hello>. Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 9.47 sec Results : Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 [INFO] [jar:jar] [INFO] Building jar: /Users/bsnyder/src/hello-world-smx/hello-world-su/target/hello-world-su-1.0-SNAPSHOT.jar [INFO] [jbi:jbi-component] [INFO] Generating installer /Users/bsnyder/src/hello-world-smx/hello-world-su/target/hello-world-su-1.0-SNAPSHOT-installer.zip [INFO] Building jar: /Users/bsnyder/src/hello-world-smx/hello-world-su/target/hello-world-----------------------------su-1.0-SNAPSHOT-installer.zip [INFO] Reactor Summary:[install:install] [INFO] Installing /Users/bsnyder/src/hello-world-smx/hello-world-su/target/hello-world-su-1.0-SNAPSHOT.jar to /Users/bsnyder/.m2/repository/org/apache/servicemix/samples/helloworld/hello-world-su/1.0-SNAPSHOT/hello-world-su-1.0-SNAPSHOT.jar [INFO] Installing /Users/bsnyder/src/hello--------------------------------------------------------- [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] world-smx/hello-world-su/target/xbean/hello-world-su.xsd to /Users/bsnyder/.m2/repository/org/apache/servicemix/samples/helloworld/hello-world-su/1.0-SNAPSHOT/hello-world-su-1.0-SNAPSHOT.xsd [INFO] Installing /Users/bsnyder/src/hello-world-smx/hello-world-su/target/xbean/hello-world-su.xsd.html to /Users/bsnyder/.m2/repository/org/apache/servicemix/samples/helloworld/hello-world-su/1.0-SNAPSHOT/hello-world-su-1.0-SNAPSHOT-schema.html [INFO] Installing /Users/bsnyder/src/hello-world-smx/hello-world-su/target/hello-world-su-1.0-SNAPSHOT-installer.zip to /Users/bsnyder/.m2/repository/org/apache/servicemix/samples/helloworld/hello-world-su/1.0-SNAPSHOT/hello-world-su-1.0-SNAPSHOT-installer.zip [INFO] ---------------------------------------------------------------------------- [INFO] Building A custom project [INFO] task-segment: [clean, install] [INFO] ---------------------------------------------------------------------------- [INFO] [clean:clean] [INFO] Deleting directory /Users/bsnyder/src/hello-world-smx/hello-world-sa/target [INFO] Deleting directory /Users/bsnyder/src/hello-world-smx/hello-world-sa/target/classes [INFO] Deleting directory /Users/bsnyder/src/hello-world-smx/hello-world-------------------------- [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.
Testing the Components
Performing automated testing of the components is possible via Maven as well. Because the ServiceMix root POM prevents tests from being executed at the top level, this functionality must be activated so that the coponents can be tested. To do so, the <build>
element of the hello-world-se/pom.xml
must be augmented using the following content:
Code Block |
---|
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>false</skip><!-- this overrides the ServiceMix root POM's setting for test execution -->
</configuration>
</plugin>
</plugins>
</pluginManagement>
|
By adding the configuation above, the install
goal will now including test execution in addition to building and packaging the components. To run the tests, execute the test
goal this time and you should see the following output:
Code Block |
---|
$ mvn test
|
No Format |
---|
[INFO] Scanning for projects... [INFO] ---sa/target/test-classes [WARNING] Artifact junit:junit:jar:3.8.1:test retains local scope 'test' overriding broader scope 'compile' given by a dependency. If this is not intended, modify or remove the local scope. [INFO] [jbi:generate-jbi-service-assembly-descriptor] [INFO] Generating jbi.xml [INFO] [resources:resources] [INFO] Using default encoding to copy filtered resources. [INFO] [compiler:compile] [INFO] No sources to compile [INFO] [resources:testResources] [INFO] Using default encoding to copy filtered resources. [INFO] [compiler:testCompile] [INFO] No sources to compile [INFO] [surefire:test] [INFO] No tests to run. [INFO] [jbi:jbi-service-assembly] [INFO] [jar:jar] [INFO] Building jar: /Users/bsnyder/src/hello-world-smx/hello-world-sa/target/hello-world-sa-1.0-SNAPSHOT.jar [INFO] [install:install] [INFO] Installing /Users/bsnyder/src/hello-world-smx/hello-world-sa/target/hello-world-sa-1.0-SNAPSHOT.jar to /Users/bsnyder/.m2/repository/org/apache/servicemix/samples/helloworld/hello-world-sa/1.0-SNAPSHOT/hello-world-sa-1.0-SNAPSHOT.zip [INFO] ---------------------------------------------------------------------------- [INFO] Building Hello World JBI Component [INFO] task-segment: [clean, install] [INFO] ---------------------------------------------------------------------------- [INFO] [clean:clean] [INFO] Deleting directory /Users/bsnyder/src/hello-world-smx/target [INFO] Deleting directory /Users/bsnyder/src/hello-world-smx/target/classes [INFO] Deleting directory /Users/bsnyder/src/hello-world-smx/target/test-classes [INFO] [site:attach-descriptor] [INFO] [install:install] [INFO] Installing /Users/bsnyder/src/hello-world-smx/pom.xml to /Users/bsnyder/.m2/repository/org/apache/servicemix/samples/helloworld/hello-world-smx/1.0-SNAPSHOT/hello-world-smx-1.0-SNAPSHOT.pom [INFO] [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Reactor Summary: [INFO] ------------------------------------------------------------------------- [INFO] BuildingA custom project ...................................... SUCCESS [30.738s] [INFO] A custom project [INFO] task-segment: [test ...................................... SUCCESS [3.080s] [INFO] Hello World JBI Component ............................. SUCCESS [1.547s] [INFO] ---------------------------------------------------------------------------- ... [INFO] [compiler:compile] ... [INFO] [surefire:test] [INFO] Setting reports dir: c:\java\tmp\servicemix-helloWorldSE\target/surefire-reports ------------------------------------------------------- T E S T S ------------------------------------------------------- [surefire] Running org.apache.servicemix.samples.helloWorldSE.MySpringComponentTest ... [surefire] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 1,422 sec----- [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ [INFO] Total time: 36 seconds [INFO] Finished at: Sat Jan 06 16:59:57 MST 2007 [INFO] BUILD SUCCESSFULFinal Memory: 15M/28M [INFO] ------------------------------------------------------------------------ ... |
Note | ||
---|---|---|
| ||
Maybe add further testing at the end of the tutarial ("how to continue when having the working example") |
Generation and Deployment of the SA
The execution of the install
goal above packages not only each component individually, it also packages the components together into a single SA. Of course, the code does not yet do anything, but we can already deploy the SA ServiceMix by switching to the hello-world-se/hello-world-sa
directory and executing the jbi:projectDeploy
goal like so:
Code Block |
---|
$ mvn jbi:projectDeploy
|
This tells the Maven JBI plugin to deploy the components to ServiceMix. When the deployment is complete, ServiceMix will output the following:
No Format |
---|
INFO - ServiceAssemblyLifeCycle - Starting service assembly: hello-world-sa
|
As long as you see the BUILD SUCCESSFUL message in the output continue to the next section to give each project a unique name.
Give Each of the Maven Subprojects a Name
Notice in the output above that there are a two projects named A custom project. This is because the archetypes create projects with this generic name. Let's give each project a unique name via each component's pom.xml
file. 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 replace<name>A custom project</name>
with<name>Hello World Service Assembly</name>
- Edit
hello-world-su/pom.xml
and replace<name>A custom project</name>
with<name>Hello World Service Unit</name>
Now when the projects are built you will no longer see a project named A custom project. Instead you'll now see Hello World Service Unit and Hello World Service Assembly. Rebuild the projects again using the mvn clean install
command on the command-line to see the changeThis output tells us that the SA was successfully deployed to ServiceMix.
...
Note | ||
---|---|---|
| ||
When working with the
The configuration above introduces the For a few more configurable options on the Maven JBI plugin, see also Ability to configure jbi:projectDeploy goal to exclude updating dependencies. |
Adding Functionality to the Component
We're now ready to add a bit of functionality to the component. Using an IDE like IntelliJ IDEA or Eclipse make this task much easier. The steps described here apply to Eclipse.
Tip | ||
---|---|---|
| ||
In order to import the SE into Eclipse, tell Maven to generate the necessary project and classpath files, switch to the
This will allow the SE to be imported into Eclipse for adding functionality. |
Note | ||
---|---|---|
| ||
The default implementation of the component accepts InOut MEPs (ADD OUTLINE for further work:
Classpath for SU to include manually till v3.1, see mail manually editing http://goopen.org/confluence/display/SM/Working+with+Service+Units INS When to use this JBI Component provide exact position in the SVN! maybe moving the content of overlapping existing docus to this new tut and - where appropriate - delete the old ones (only leaving a redirect). This shall already include everything stated at provide additional reading |
...