Unable to compile java file containing apache camel program

397 Views Asked by At

I am a beginner at using Apache Camel. I have a maven project with the following structure:

enter image description here

File Write_Paper contains the content below:

enter image description here

When I compile this file by using cmd with: javac Write_Paper.java, I get some errors:

Write_Paper.java:3: error: package org.apache.camel does not exist
import org.apache.camel.CamelContext;

Write_Paper.java:4: error: package org.apache.camel.builder does not exist
import org.apache.camel.builder.RouteBuilder;

Write_Paper.java:5: error: package org.apache.camel.impl does not exist
import org.apache.camel.impl.DefaultCamelContext;

Write_Paper.java:9: error: cannot find symbol
        CamelContext context = new DefaultCamelContext()

  symbol:   class CamelContext
  location: class Write_Paper
Write_Paper.java:9: error: cannot find symbol

  symbol:   class DefaultCamelContext
  location: class Write_Paper
Write_Paper.java:10: error: cannot find symbol
        context.addRoutes(new RouteBuilder() {

  symbol:   class RouteBuilder
  location: class Write_Paper
Write_Paper.java:12: error: cannot find symbol
                from("file:sourceFolder?noop=true")

  symbol: method from(String)

7 errors

pom.xml file content here

enter image description here

I have tried many solutions but I cannot fix them. what should I do to fix it?

1

There are 1 best solutions below

3
On

Pom.xml

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-core</artifactId>
    <version>3.20.2</version>
</dependency>
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
    <version>1.6.6</version>
</dependency>

Standalone java code

import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
    
public class HelloWorld {
    public static void main(String[] args) throws Exception {
        CamelContext context = new DefaultCamelContext();
        context.addRoutes(new RouteBuilder() {
            public void configure() {
                from("file:source?noop=true").to("file:dest");
            }
        });
        context.close();
        context.start();
    }
}

keep the file inside the src/main/resources folder:

file name = log4j.properties inside file content:

log4j.rootLogger=debug,console

log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.Target=System.out
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d [%t] %-5p %L - %m%n

It should work.