Camel Lesson 4: Using maven to set up a Camel project

In this Camel tutorial we will learn how to set up a basic Camel project using a Maven archetype which is based on Spring XML configuration file.

There are a few different approaches to configuring components and endpoints.

1. You can explicitly configure a Component using Java code as shown in this example:

context.addRoutes(new RouteBuilder() {
    public void configure() {

2. You can configure your Component or Endpoint instances in your Spring XML. When using Spring the CamelContext can be pre configured based on defined beans in spring XML.

The advantage of using Spring based Camel project is that you can build complex Camel routes declaratively, that is just by filling up the Camel Spring configuration file, named camel-context.xml

We will show here how to build a Spring based Camel project using a Maven Archetype:

mvn archetype:generate                    






Here is camel-context.xml which contains the route definition:

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns=""

  <camel:camelContext xmlns="">
      <camel:from uri="file:src/data?noop=true"/>
          <camel:xpath>/person/city = 'London'</camel:xpath>
          <camel:log message="UK message"/>
          <camel:to uri="file:target/messages/uk"/>
          <camel:log message="Other message"/>
          <camel:to uri="file:target/messages/others"/>


What is doing this route is pretty simple: it takes (without removing them, as there is the noop=true option) as input XML files contained in the src/data folder.

These files are processed using an XPath expression which checks for the Path /person/city. If the path belongs to London, files are moved in the target/messages/uk folder. Otherwise files are moved in the target/messages/others folder.

Run the Maven project using:

mvn camel:run


Cookie Alert