Embedding Camel in a Dynamic Web project containing Stardust facet

Using Maven for dependency management

If you are using Maven to create you dynamic web project, you need only to add the Camel project as a dependency. If you followed the Spring file naming recommendation, you will be able to load Camel context. Otherwise you need to update your web.xml accordingly.

<context-param>
	<param-name>contextConfigLocation</param-name>
	<param-value>WEB-INF/config/ipp/spring/*-context.xml,classpath*:META-INF/spring/*-context.xml</param-value>
</context-param>

Technically, Camel is a Java application. To use it, you just need to add its JARs to your project's class-path. But using Maven to access these JARs will make your life easier. As a best practice, we recommend you to create Camel applications with Maven archetypes. The Maven archetypes that are provided will get you started much faster. Another recommendation is to manage your application's dependencies with Maven. You can use whatever build system you like to develop your Camel projects but when you Use Maven you focus more on your business code than the library dependencies.

Manual dependency management

Steps to Integrate Camel:

Below are the mains steps to integrate Camel in your dynamic project, if you are not using Maven to manage the dependencies:

  • Create a standard dynamic web project containing Stardust facet.
  • Create a new Maven project using camel-archetype-spring or camel-archetype-java.
  • Connect the utility project to the web project by configuring a Java EE module dependency.
  • Embedding Camel in a Dynamic Web project containing Stardust facet:

    If you need to embed your project within a standard dynamic web project containing Stardust facet, you need to copy your dependency jar files into WEB-INF/lib directory manually or using Maven dependency plug-in. To use Maven dependency plug-in, you need to update your Maven project pom.xml by adding the following configuration:

    <plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-dependency-plugin</artifactId>
       <version>2.1</version>
       <executions>
          <execution>
      <id>copy-dependencies</id>
      <phase>package</phase>
      <goals>
         <goal>copy-dependencies</goal>
      </goals>
             <configuration>
             <outputDirectory>PATH_TO_DYNAMIC_PROJECT/WebContent/WEB-INF/lib</outputDirectory>
             <overWriteReleases>false</overWriteReleases>
             <overWriteSnapshots>true</overWriteSnapshots>
             <excludeTransitive>true</excludeTransitive>
            </configuration>
          </execution>
       </executions>
    </plugin>
    

    To copy the dependencies file, you need to execute the following command: mvn package. Then you have to connect the Maven project containing your routes to the web project by configuring a Java EE module dependency. For more information on how to use the utility project please visit: Utility Projects

    Now you can run your web project and in the log file you should be able to see that Camel is starting.

    INFO  [main      ] GlobalParameters          - Loading properties via provider factory org.eclipse.stardust.engine.api.spring.web.SpringAppContextPropertiesProviderFactory (priority 4).
    INFO  [main      ] ContextPropertiesProvider -   org.eclipse.stardust.engine.api.spring.cachedApplicationContext = null
    INFO  [main      ] EngineService             - Bootstrapping engine
    INFO  [main      ] CacheHelper               - No caching service is available.
    INFO  [main      ] UIController              - Initializing UIController.
    INFO  [main      ] SpringCamelContext        - Apache Camel 2.7.1 (CamelContext: camelContext) is starting
    INFO  [main      ] SpringCamelContext        - JMX enabled. Using ManagedManagementStrategy.
    INFO  [main      ] tationTypeConverterLoader - Found 3 packages with 13 @Converter classes to load
    INFO  [main      ] DefaultTypeConverter      - Loaded 148 type converters in 0.345 seconds
    INFO  [main      ] SpringCamelContext        - Route: route1 started and consuming from: Endpoint[direct://start]
    INFO  [main      ] SpringCamelContext        - Total 1 routes, of which 1 is started.
    INFO  [main      ] SpringCamelContext        - Apache Camel 2.7.1 (CamelContext: camelContext) started in 0.668 seconds
    INFO  [main      ] ContextLoader             - Root WebApplicationContext: initialization completed in 3614 ms