Starting your HelloWorld in Apache Camel using windows command prompt

Hi,

If you are starting your journey into apache camel, then this article might help you to write a simple camel program in notepad and execute it. The program is written using Java DSL and exeucted in windows command prompt. Before we start, there are 2 pre-requisites that need to be followed.

Pre-requisite:

1. Camel core jar of any version. (For the demo i am using the version 2.15.1)

2. slf4j jar

Task:

We are going to perform a simple file movement task from one windows folder to another. All the files present within the folder will be moved when the program is executed.

1. Create a directory in your windows system as shown below. We will take the directory src_files as the source directory from where we will copy the files into dest directory.

dir structure
Initial directory structure

2. For simplicity, i have put the jar file(s) and the java source file within the same folder.

3. Start coding your program as shown below.

program

4. Compile the java file as shown below. If everything went fine, the compiler will return successfully.

javac -cp camel-core-2.15.1.jar CamelDemo.java

5. Run the java program as,

java -cp .;camel-core-2.15.1.jar;slf4j-api-1.6.6.jar CamelDemo

This will produce the output as shown below:

Executing camel route…..
Copying of the files finished….please check the destination directory

6. That’s it. You have successfully executed your first camel route and you can verify the files in the directory as,

output dir structure

As you can see the files 11.txt and 12.txt are copied into the dest folder and the route got finished successfully.

Take Away from the exercise:

1. The input URI used in this example is “file:D:/Camel_Programs/src_files?noop=true”.

2. An Endpoint is configured using an URI.

3. When the program was run, Camel internally used utility classes (e.g., GenericFileComponent, etc) to copy the files from one location to another location.

4. When changes are to be made to a route, Spring DSL is preferred when compared to Java DSL since modifications to the routes can easily be done in the spring XML file.

For further readings, please refer to the Camel’s official website.

http://camel.apache.org/

Thanks,

Kalyan

Leave a comment