我编写了一个小型 Camel 应用程序(https://github.com/bhushantimilsina/camel-simple-app),它从收件箱目录读取文件,调用处理器更改其大小写并将输出写入发件箱目录中的文件。当我运行主类(使用 IDE 或使用 run.cmd 脚本)时,一切都按预期工作,但是当我使用可执行 JAR 运行应用程序时,只有消息内容为空。
为了做这个测试,我复制了 \target 中的 \inbox\inputFile.txt 以便输入文件在那里。然后我使用目标目录中的“java -jar camel-simple-app-1.0-jar-with-dependencies.jar”运行 JAR。
作为可执行 JAR 运行时的输出日志:
2021-03-04 20:04:46.581| INFO | AbstractCamelContext.java 2980 | Routes startup summary (total:4 started:4)
2021-03-04 20:04:46.581| INFO | AbstractCamelContext.java 2985 | Started inputFileRoute (file://inbox)
2021-03-04 20:04:46.581| INFO | AbstractCamelContext.java 2985 | Started multicastRoute (direct://inputChannel)
2021-03-04 20:04:46.581| INFO | AbstractCamelContext.java 2985 | Started upperCaseTransformRoute (direct://upperCaseTransformInputChannel)
2021-03-04 20:04:46.581| INFO | AbstractCamelContext.java 2985 | Started lowerCaseTransformRoute (direct://lowerCaseTransformInputChannel)
2021-03-04 20:04:46.581| INFO | AbstractCamelContext.java 2997 | Apache Camel 3.8.0 (camelContext) started in 234ms (build:31ms init:172ms start:31ms)
2021-03-04 20:04:46.612| INFO | AbstractCamelContext.java 2980 | Routes startup summary (total:0 started:0)
2021-03-04 20:04:46.612| INFO | AbstractCamelContext.java 2997 | Apache Camel 3.8.0 (camel-1) started in 15ms (build:0ms init:15ms start:0ms)
2021-03-04 20:04:47.581| INFO | CamelLogger.java 166 | *** Input message read from file: C:\SpringPractice\camel-simple-app\target\inbox\inputFile.txt**
2021-03-04 20:04:47.581| INFO | CamelLogger.java 166 | *** Message:
2021-03-04 20:04:47.581| INFO | CamelLogger.java 166 | *** Multicasting the file content to different processors ...
2021-03-04 20:04:47.628| INFO | CamelLogger.java 166 | *** Transforming the message to upper case
2021-03-04 20:04:47.628| INFO | CamelLogger.java 166 | *** Transforming the message to lower case
2021-03-04 20:04:47.628| ERROR | CamelLogger.java 205 | Failed delivery for (MessageId: F89B7EA52A14215-0000000000000001 on ExchangeId: F89B7EA52A14215-0000000000000001). Exhausted after delivery attempt: 1 caught: java.lang.NullPointerException
在日志中,消息:为空。
从 IDE 运行或使用 run.cmd 脚本时,我可以在文件中看到消息:打印消息。
2021-03-04 20:12:44.320| INFO | AbstractCamelContext.java 2980 | Routes startup summary (total:4 started:4)
2021-03-04 20:12:44.336| INFO | AbstractCamelContext.java 2985 | Started inputFileRoute (file://inbox)
2021-03-04 20:12:44.336| INFO | AbstractCamelContext.java 2985 | Started multicastRoute (direct://inputChannel)
2021-03-04 20:12:44.336| INFO | AbstractCamelContext.java 2985 | Started upperCaseTransformRoute (direct://upperCaseTransformInputChannel)
2021-03-04 20:12:44.336| INFO | AbstractCamelContext.java 2985 | Started lowerCaseTransformRoute (direct://lowerCaseTransformInputChannel)
2021-03-04 20:12:44.336| INFO | AbstractCamelContext.java 2997 | Apache Camel 3.8.0 (camelContext) started in 422ms (build:78ms init:312ms start:32ms)
2021-03-04 20:12:44.383| INFO | AbstractCamelContext.java 2980 | Routes startup summary (total:0 started:0)
2021-03-04 20:12:44.383| INFO | AbstractCamelContext.java 2997 | Apache Camel 3.8.0 (camel-1) started in 16ms (build:0ms init:16ms start:0ms)
2021-03-04 20:12:45.351| INFO | CamelLogger.java 166 | *** Input message read from file: C:\SpringPractice\camel-simple-app\inbox\inputFile.txt
2021-03-04 20:12:45.351| INFO | CamelLogger.java 166 | *** Message: SoMe meESSage GOes HERe
2021-03-04 20:12:45.351| INFO | CamelLogger.java 166 | *** Multicasting the file content to different processors ...
2021-03-04 20:12:45.398| INFO | CamelLogger.java 166 | *** Transforming the message to lower case
2021-03-04 20:12:45.398| INFO | CamelLogger.java 166 | *** Transforming the message to upper case
2021-03-04 20:12:46.383| INFO | AbstractCamelContext.java 3174 | Apache Camel 3.8.0 (camel-1) shutting down (timeout:45s)
2021-03-04 20:12:46.383| INFO | AbstractCamelContext.java 3368 | Routes shutdown summary (total:0 stopped:0)
2021-03-04 20:12:46.383| INFO | AbstractCamelContext.java 3313 | Apache Camel 3.8.0 (camel-1) shutdown in 0ms (uptime:2s)