Camel-K无法识别本地软件包

u0njafvf  于 2022-11-07  发布在  Apache
关注(0)|答案(1)|浏览(165)

我有一个RouteBuilder类,它使用自己的处理器。当使用Maven在Camel本地运行时,它运行得很好。但是,当我尝试使用camel-k时,它说它找不到包。我需要做什么吗?

我的处理器

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");
        }
    }
}

路由器

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");
    }
}

我正在使用minikube并运行以下命令: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;
ppcbkaq5

ppcbkaq51#

这是意料之中的,因为camel-k不知道在哪里可以找到处理器的类,因此您有两个选择:
1.将处理器嵌入为路由的内部类
1.将您的处理器打包为一个Maven工件(您也可以使用jitpack来避免在测试时将其发布到Maven存储库),并将其列为任何其他依赖项

相关问题