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

Compare with Current View Page History

« Previous Version 3 Next »

About the Groovy DSL

The Groovy DSL implementation is built on top of the existing Java-based DSL, but it additionally allows to use Groovy language features in your routes, particularly Closures acting as processor, expression, predicate, or aggregation strategy.
With the Groovy DSL you write your RouteBuilder classes entirely in Groovy, while the scripting component allows to embed small scripts into Java routes. The Groovy DSL requires Groovy 2.0 or newer and is available as of Camel 2.11.

Developing with the Groovy DSL

To use the Groovy DSL in your camel routes you need to add the a dependency on *camel-groovy which implements the Groovy DSL.

If you use Maven you can just add the following to your pom.xml, substituting the version number for the latest & greatest release (see the download page for the latest versions).

<dependency>
  <groupId>org.apache.camel</groupId>
  <artifactId>camel-groovy</artifactId>
  <version>2.11.0</version>
</dependency>

Additionally you need to make sure that the Groovy classes will be compiled. You can either use gmaven for this or, particularly with mixed projects containing Java and Groovy code, you might want to use the Groovy Eclipse compiler:

  <plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
      <compilerId>groovy-eclipse-compiler</compilerId>
    </configuration>
    <dependencies>
      <dependency>
        <groupId>org.codehaus.groovy</groupId>
        <artifactId>groovy-eclipse-compiler</artifactId>
	<version>2.7.0-01</version>
      </dependency>
    </dependencies>
  </plugin>

As Eclipse user, you might want to configure the Maven Eclipse plugin in a way so that your project is set up correctly for using Eclipse Plugin for Groovy when mvn eclipse:eclipse is executed:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-eclipse-plugin</artifactId>
    <configuration>
      <additionalProjectnatures>
        <projectnature>org.eclipse.jdt.groovy.core.groovyNature</projectnature>
      </additionalProjectnatures>
      <classpathContainers>
        <classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer>
        <classpathContainer>GROOVY_DSL_SUPPORT</classpathContainer>
      </classpathContainers>              
    </configuration>
  </plugin>	  
  • No labels