Camel-K does not recognize local package

1k views Asked by At

I have a RouteBuilder class that is using its own Processor. When running locally in Camel using Maven, it runs fine. However, when I try to use camel-k, it says it cannot find the package. Is there something I need to do?

MyProcessor

package com.test.processor;

import java.io.File;

import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.Processor;
import org.apache.camel.component.file.GenericFile;

public class MyProcessor implements Processor {

    public void process(Exchange exchange) throws Exception {
        Message inMsg = exchange.getIn();
        Object body = inMsg.getBody();
        
        if (body instanceof File) {
            System.out.println("Is a FILE");
        } else {
            System.out.println("Not a FILE");   
        }
        
        if (body instanceof GenericFile) {
            System.out.println("Is a GF for sure");
            GenericFile gf = (GenericFile) body;
            String fileName = gf.getFileName();
            
            System.out.println("Filename: " + fileName);
        } else {
            System.out.println("NOT a GF");
        }
    }
}

Router

package com.javainuse.route;

import org.apache.camel.builder.RouteBuilder;
import com.test.processor.MyProcessor;

public class SimpleRouteBuilder extends RouteBuilder {

    @Override
    public void configure() throws Exception {
        // Transfer files from one another using a processor
        from("file:C:/inputFolder?noop=true")
            .process(new MyProcessor())
            .to("file:C:/outputFolder")
            .setBody().simple("Test")
            .log("Test log");
    }
}

I am using minikube and run the command: kamel run SimpleRouteBuilder.java --dev

[1] Exception in thread "main" org.apache.camel.RuntimeCamelException: org.joor.ReflectException: Compilation error: /com/test/route/SimpleRouteBuilder.java:4: error: package com.test.processor does not exist
[1] import com.test.processor.MyProcessor;
1

There are 1 answers

4
Luca Burgazzoli On BEST ANSWER

This is expected as camel-k does not know where to find the classes for your processor so you have two options:

  1. embed the processor as inner class of your route
  2. package your processor as a maven artifact (you can also use jitpack to avoid having to publish it to a maven repo while testing) and list it as any other dependency