命令行中 Apache Camel 3.14.0 的正确 class 到 运行 是什么?

What's the correct class to run Apache Camel 3.14.0 from command line?

我设置以下 pom.xml 以使用 Camel 3.14.0:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

   <modelVersion>4.0.0</modelVersion>
   <groupId>com.apps</groupId>
   <artifactId>MyApp</artifactId>
   <version>1.0.0</version>
   <name>MyApp Camel component</name>

   <dependencyManagement>
     <dependencies>
       <dependency>
         <groupId>org.apache.camel</groupId>
         <artifactId>camel-bom</artifactId>
         <version>3.14.0</version>
         <type>pom</type>
         <scope>import</scope>
       </dependency>
     </dependencies>
   </dependencyManagement>
   
   
   <dependencies>
      <dependency>
         <groupId>org.apache.camel</groupId>
         <artifactId>camel-core</artifactId>
      </dependency>
      <dependency>
         <groupId>org.apache.camel</groupId>
         <artifactId>camel-csv</artifactId>
      </dependency>
   
      <dependency>
         <groupId>org.apache.camel</groupId>
         <artifactId>camel-sql</artifactId>
      </dependency>
      <dependency>
         <groupId>org.apache.camel</groupId>
         <artifactId>camel-spring</artifactId>
      </dependency>
      
   
      <!-- DB dependencies -->  
      <dependency>
          <groupId>org.hsqldb</groupId>
          <artifactId>hsqldb</artifactId>
          <version>2.6.1</version>
          <scope>system</scope>
          <systemPath>D:\Drivers\hsqldb-2.6.1-jdk8.jar</systemPath> 
      </dependency>
   </dependencies>
</project>

然后我在 Windows 中有这个命令行来收集依赖项:

C:\Users\Public\apache-maven-3.2.5\bin\mvn -f pom.xml dependency:copy-dependencies

当我 运行 它时,我得到目标文件夹中的所有 jar (../build/target/dependency)。

然后我得到其他 run.bat 文件如下:

set CLASSPATH=../build/target/dependency/*;../config/    

java -classpath "%CLASSPATH%" org.apache.camel.spring.Main

但是当我 运行 它时,我收到一条错误消息说它找不到 Main class。 class 是以前用例(Camel 2.10.6)中使用的那个,它运行良好。能否请您指点一下 class 此处引用的正确内容?

编辑 1: 我在文档中发现 Main 现在在 org.apache.camel.main 中,所以我在 run.bat 中配置了它,它似乎是 运行宁。但现在它显示以下内容,奇怪的是它停止从 context.xml 中配置的路径中选取文件。有什么想法吗?

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.

编辑 2: 我查看了错误并发现我需要包含依赖项

  <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-slf4j-impl</artifactId>
  </dependency>

它似乎仍然有效(关于 slf4 的消息消失了)但仍然无法从路径中选择文件。

现在,我决定转向最后一个 LTS 版本的原因是因为我需要使用一个组件 属性 只在比我一直使用的更新版本的 Camel 中可用。所以我决定试一试最新版本,但现在我遇到错误,说找不到 class.

我过去使用过 Camel,但只是基于其他人提供的示例,而不是从头开始,所以我根本不是专家,不幸的是我需要尽快解决这个问题。我想最简单的方法是使用 java bean,但我不是 java 开发人员,所以我认为使用 Spring XML DSL 可能没问题。我正在使用 java 1.8.0_92.

Camel 文档似乎没有按照 spring xml 提供那么多详细信息,因此我们将不胜感激任何帮助。

框架和文档

首先,理解 Apache Camel 是集成框架,Spring 是 应用程序框架 最显着的特征是依赖注入。因此,文档有点希望开发人员熟悉 spring-框架,并能够在 camel 和 spring 文档之间兼顾。

骆驼主菜

另一方面,Camel-main 是您可以在没有任何框架的情况下用于 运行 camel 应用程序的工具,因此它不了解 spring 框架。有 camel-spring-main 但稍后会详细介绍。

Spring-开机

当谈到 spring 时,使用 spring-boot 可能更容易,您可以将其视为 maven 依赖项的集合,您可以使用它来自动配置 spring 具有默认配置的应用程序。

我建议您使用 camel maven archetype camel-archetype-spring-boot 创建一个新项目。这应该为您提供良好的起点和示例,说明如何开始使用骆驼和 spring。

要将 spring-xml 文件与 camel-spring-boot 一起使用,您可以在 SpringBootApplication [=57= 上添加注释 @ImportResource(classpath:META-INF/spring/camel-context.xml) ](class 注释为 @SpringBootApplication,使用模板时命名为 MySpringBootApplication)。

更改路径以匹配您的 xml 文件的位置和名称,并从项目中删除或注释示例 RouteBuilder class 以防止它被任何东西打断。

# You can run spring-boot application using maven
mvn spring-boot:run

# Alternatively you should be able to run it from jar using
java -jar application.jar

spring-boot 的缺点是它会用大量额外的依赖项淹没我们的项目。例如,仅保留应用程序 运行ning 模板项目使用 spring-boot-start-webspring-boot-starter-undertowspring-boot-starter-actuator 依赖项。

骆驼Spring主要

还有原型 camel-archetype-spring,您可以使用它来创建没有 spring-boot 的 camel spring 应用程序。它使用我上面提到的 camel-spring-main 并且可以 运行 使用 maven 和命令 mvn camel:run.

不过我觉得这个原型有点欠缺。首先,它缺少可见的 main class,如果将它与某些 camel-archetype-main 进行比较,这是不一致的。其次,它的包装配置似乎有问题,因为我没有找到从 jar 中 运行 它的简单方法。我尝试的大多数尝试导致 ClassNotFoundException for org/apache/camel/spring/Main 甚至艰难我拥有所有 maven 依赖项。不过 运行 从 IDE 开始没问题。

将您的项目转换为 JAVA-DSL 并使用 camel main

由于您的路线似乎并不那么复杂,您可以在几分钟内将其从 XML 转换为 Java-DSL,并且只需 运行 它与 camel-main 没有任何应用程序框架。这有一个原型,叫做 camel-archetype-main。