Camel-K不识别本地包。

huangapple go评论66阅读模式
英文:

Camel-K does not recognize local package

问题

我有一个RouteBuilder类它使用自己的Processor在使用Maven在Camel中本地运行时它可以正常运行然而当我尝试使用camel-k时它说找不到该包我需要做些什么吗

**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("是一个文件");
            } else {
                System.out.println("不是一个文件");    
            }
            
            if (body instanceof GenericFile) {
                System.out.println("肯定是一个通用文件");
                GenericFile gf = (GenericFile) body;
                String fileName = gf.getFileName();
                
                System.out.println("文件名:" + fileName);
            } else {
                System.out.println("不是一个通用文件");
            }
        }
    }

**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 {
            // 使用Processor从一个地方传输文件到另一个地方
            from("file:C:/inputFolder?noop=true")
                .process(new MyProcessor())
                .to("file:C:/outputFolder")
                .setBody().simple("测试")
                .log("测试日志");
        }
    }

我正在使用`minikube`并运行命令
`kamel run SimpleRouteBuilder.java --dev`

    [1] 异常线程 "main" org.apache.camel.RuntimeCamelException: org.joor.ReflectException: 编译错误/com/test/route/SimpleRouteBuilder.java:4: 错误包com.test.processor不存在
    [1] import com.test.processor.MyProcessor;
英文:

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

得分: 3

这是预期的,因为camel-k不知道在哪里找到处理器的类,所以您有两个选择:

  1. 将处理器嵌入到路由的内部类中
  2. 将处理器打包为Maven构件(您还可以使用jitpack,在测试时避免将其发布到Maven仓库),并将其列为任何其他依赖项
英文:

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

huangapple
  • 本文由 发表于 2020年9月22日 09:01:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/64001719.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定