Camel Maven Plugin
The Camel Maven Plugin allows you to run your Enterprise Integration Patterns using Spring for Dependency Injection inside Maven along with being able to support Visualisation along with integration of the Visualisation diagrams into the standard maven reports for your project.The following
Goals
...
Supported
Documentation | Reference Goal | Description |
---|---|---|
camel:run | Boots up Camel in a new JVM the context of a separately initiated Java thread using the Spring configuration at META-INF/spring/*.xml and runs your routing rules. From Camel 2.10 onwards also OSGi blueprint is supported to load from OSGI-INF/blueprint/*.xml (requires to configure the plugin to use blueprint). | |
camel:embedded | Boots up Camel in the same JVM as Maven using the Spring configuration at META-INF/spring/*.xml and runs your routing rules. From Camel 2.10 onwards also OSGi blueprint is supported to load from OSGI-INF/blueprint/*.xml (requires to configure the plugin to use blueprint). | |
camel:docdot | deprecated: Generates DOT files and then HTML, PNG, SVG files for your EIP routing rules with integration into Maven Reports |
Running your routing rules via camel:run
camel:run is used to run Camel Spring configurations inside Maven for easy testing. A good example application to get you started is the Spring Example.
Code Block |
---|
cd examples/camel-example-spring
mvn camel:run
|
How this works is that the plugin will compile the source code in the maven project, then boot up a Spring ApplicationContext using the XML confiuration files on the classpath at
Code Block |
---|
META-INF/spring/*.xml
|
This allows you to boot up any Spring services you wish; whether they are Camel related or any other Spring POJOs.
Running your rules via camel:embedded
camel:embedded works the same as the camel:run above, but it does not fork another JVM, but instead boots up a new ClassLoader and loads the routing rules inside that. So it should startup a bit quicker. Though sometimes we all get the odd classpath issue; so sometimes forking a new JVM can work around any strange Maven classpath issues.
Visualiation Maven Reports
Camel supports Visualisation to be able to turn your Enterprise Integration Patterns into a nice graphical represenation.
If you run the camel:doc plugin it will boot up your CamelContext just like the camel:run plugin but it will only keep up for a few seconds. During that time
it will generate a DOT file generated in target/site/cameldoc. Then this DOT file will be converted nicely into a HTML report.
Code Block |
---|
mvn camel:doc
|
. This plugin only supports Spring XML files. | ||
camel:validate | camel:validate | Camel 2.19: To validate your source code for invalid Camel endpoint uris. |
Adding the plugin to your pom.xml
Add the following in your <build><plugins> section
Note |
---|
You may override the default Spring application context file uri META-INF/spring/*.xml by using the applicationContextUri property in the camel-maven-plugin configuration. Paths may be split using a semi-colon (;). |
Code Block | ||
---|---|---|
| ||
<plugin>
<groupId>org.apache.camel</groupId>
<artifactId>camel-maven-plugin</artifactId>
<configuration>
<applicationContextUri>META-INF/spring/*.xml;YOUR_FILE_NAME_IN_THE_CLASS_PATH.xml</applicationContextUri>
</configuration>
</plugin>
|
You can also specify what Main class to use when running the plugin. By default this is org.apache.camel.spring.Main
.
Code Block | ||
---|---|---|
| ||
<plugin>
<groupId>org.apache.camel</groupId>
<artifactId>camel-maven-plugin</artifactId>
<!-- optional, default value: org.apache.camel.spring.Main -->
<configuration>
<mainClass>mypackage.boot.camel.CamelStartup</mainClass>
</configuration>
</plugin>
|
File based spring configuration files
From Camel 1.4 onwards loading Spring context files via a file location is also supported. You configure this with the fileApplicationContextUri option. Paths may be split using a semi-colon (;). This sort of file location is useful for web application projects that store spring configuration files in WEB-INF. It can also be used to replace configuration that requires an OSGi container with an equivalent non-OSGi configuration.
Code Block | ||
---|---|---|
| ||
<plugin>
<groupId>org.apache.camel</groupId>
<artifactId>camel-maven-plugin</artifactId>
<configuration>
<fileApplicationContextUri>
src/main/webapp/WEB-INF/camel*.xml;
src/test/spring/test-context.xml
</fileApplicationContextUri>
</configuration>
</plugin>
|
Classpath
The plugin will construct a classpath of any Maven dependency with scope "compile". The classpath is output as an INFO log statement upon startup.
Route Information
Information about the generated routes is available through the GraphViz report, and also through the log statements generated by the run goal. If you would like to see this information then add a log4j (or other commons-logging implementation) config file with the following levels.
Code Block | ||
---|---|---|
| ||
log4j.rootLogger=INFO, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
log4j.logger.org.apache.camel.impl.DefaultCamelContext=DEBUG, stdout
log4j.additivity.org.apache.camel.impl.DefaultCamelContext=false
|
This should produce a log statement similar to:
Code Block |
---|
670 [org.apache.camel.spring.Main.main()] DEBUG org.apache.camel.impl.DefaultCamelContext
- Adding routes from: Routes: [Route[ [From[jms:queue:queueA]] -> [To[jms:queue:queueB], To[jms:queue:queueC]]]] routes: []
|
...
Integration into Maven Reports
If you add the camel-maven-plugin to your <reporting> section of your pom you will automatically get the Visualisation reporting generated for your project as part of the regular maven site generation.
For example add the following into your pom
Code Block | ||
---|---|---|
| ||
<project>
...
<reporting>
<plugins>
<plugin>
<groupId>org.apache.camel</groupId>
<artifactId>camel-maven-plugin</artifactId>
</plugin>
</plugins>
</reporting>
</project>
|
Then when you run
Code Block | ||
---|---|---|
| ||
mvn site
|
Your context will be booted up via the META-INF/spring/*.xml files, the DOT file generated and a nice HTML report created.
Info | ||
---|---|---|
| ||
Note to get the nice HTML, PNG and SVG outputs from the DOT files you will need to install the GraphViz DOT executable and add it to your PATH so that the plugin can invoke DOT to generate the PNG/SVG files. For more details see the camel:dot. |