这是用户在 2024-12-18 14:15 为 https://camel.apache.org/manual/camel-maven-plugin.html 保存的双语快照页面,由 沉浸式翻译 提供双语支持。了解如何保存?

Camel Maven Plugin camel maven 插件

The Camel Maven Plugin supports the following goals
骆驼 Maven 插件支持以下目标

  • camel:run - To run your Camel application
    camel:run - 运行您的 Camel 应用程序

  • camel:dev - To run your Camel application in developer mode
    camel:dev - 以开发者模式运行 Camel 应用程序

  • camel:debug - To run your Camel application in debug mode
    camel:debug - 在调试模式下运行 Camel 应用程序

  • camel:prepare-fatjar - To prepare your Camel application for being packaged as a fat-jar (such as by maven-assembly-plugin)
    camel:prepare-fatjar - 准备将 Camel 应用程序打包为 fat-jar(如通过 maven-assembly-plugin 打包)

camel:run

The camel:run goal of the Camel Maven Plugin is used to run your Camel Spring configurations in a forked JVM from Maven. A good example application to get you started is the Spring Example.
Camel Maven Plugin 的 camel:run 目标用于在来自 Maven 的分叉 JVM 中运行 Camel Spring 配置。一个很好的示例应用程序是 Spring Example,它可以帮助你开始使用。

cd examples/camel-example-spring
mvn camel:run

This makes it very easy to spin up and test your routing rules without having to write a main(…​) method; it also lets you create multiple jars to host different sets of routing rules and easily test them independently.
这样,无需编写 main(...) 方法,就能非常容易地启动和测试路由规则;还能创建多个 jar 来托管不同的路由规则集,并轻松地对它们进行独立测试。

How this works is that the plugin will compile the source code in the maven project, then boot up a Spring ApplicationContext using the XML configuration files on the classpath at META-INF/spring/*.xml
其工作原理是,插件将编译 maven 项目中的源代码,然后使用类路径 META-INF/spring/*.xml 中的 XML 配置文件启动 Spring ApplicationContext。

If you want to boot up your Camel routes a little faster, you could try the camel:embedded instead.
如果想让 Camel 路由启动得更快一些,可以尝试使用 camel:embedded 代替。

Options 选项

The maven plugin run goal supports the following options which can be configured from the command line (use -D syntax), or defined in the pom.xml file in the <configuration> tag.
maven 插件运行目标支持以下选项,这些选项可通过命令行配置(使用 -D 语法),或在 pom.xml 文件的 <configuration> 标记中定义。

Parameter 参数

Default Value 默认值

Description 说明

duration 会期

-1

Sets the time duration (seconds) that the application will run for before terminating. A value ⇐ 0 will run forever.
设置应用程序在终止前运行的持续时间(秒)。值 ⇐ 0 将永远运行。

durationIdle 闲置时间

-1

Sets the idle time duration (seconds) duration that the application can be idle before terminating. A value ⇐ 0 will run forever.
设置应用程序终止前的空闲持续时间(秒)。值 ⇐ 0 将永远运行。

durationMaxMessages 最大持续时间

-1

Sets the duration of maximum number of messages that the application will process before terminating.
设置应用程序在终止前处理信息的最大数量。

logClasspath 日志路径

false 错误

Whether to log the classpath when starting
是否在启动

loggingLevel 日志级别

OFF

Whether to use built-in console logging (uses log4j), which does not require to add any logging dependency to your project. However, the logging is fixed to log to the console, with a color style that is similar to Spring Boot. You can change the root logging level to: FATAL, ERROR, WARN, INFO, DEBUG, TRACE, OFF
是否使用内置控制台日志(使用 log4j),这不需要在项目中添加任何日志依赖关系。不过,日志会固定记录到控制台,颜色风格与 Spring Boot 相似。你可以将根日志级别更改为致命、错误、警告、信息、调试、跟踪、关闭

profile 概况

To run with a specific Camel Main profile (dev,test,prod)
使用特定的 Camel 主配置文件(dev、test、prod)运行

Logging the classpath 记录类路径

You can configure whether the classpath should be logged when camel:run executes. You can enable this in the configuration using:
您可以配置在执行 camel:run 时是否记录类路径。你可以在配置中使用

<plugin>
  <groupId>org.apache.camel</groupId>
  <artifactId>camel-maven-plugin</artifactId>
  <configuration>
    <logClasspath>true</logClasspath>
  </configuration>
</plugin>

Using built-in logging 使用内置日志

If you want quickly to have logging to console, you can use the built-in logging by setting the logging level as shown:
如果想快速将日志记录到控制台,可以通过设置如图所示的日志记录级别来使用内置日志记录:

<plugin>
  <groupId>org.apache.camel</groupId>
  <artifactId>camel-maven-plugin</artifactId>
  <configuration>
    <loggingLevel>INFO</loggingLevel>
  </configuration>
</plugin>

This runs the application with console logging, in color that is similar to Spring Boot logging. This is default turned off, to use the configured logging system in the project.
该选项以控制台日志方式运行应用程序,颜色与 Spring Boot 日志类似。默认关闭此选项,以使用项目中配置的日志系统。

The idea with the built-in logging is that you sometimes want to avoid messing with setting up logging, and just want a quick and easy log to console that looks good.
使用内置日志的初衷是,有时你不想费力设置日志,只想快速、简单地将日志记录到控制台,而且看起来还不错。

camel:dev

The camel:dev is an extension to camel:run to run the Camel application in developer mode. In this mode, among others, Camel will use hot-reloading of DSL routes (xml, yaml and java) that are located from the src/main/resources directory.
camel:devcamel:run 的扩展,用于在开发人员模式下运行 Camel 应用程序。在这种模式下,Camel 将使用热加载位于 src/main/resources 目录中的 DSL 路由(xml、yaml 和 java)。

Options 选项

The maven plugin dev goal supports the following options which can be configured from the command line (use -D syntax), or defined in the pom.xml file in the <configuration> tag.
maven 插件开发目标支持以下选项,这些选项可通过命令行配置(使用 -D 语法),或在 pom.xml 文件的 <configuration> 标记中定义。

Parameter 参数

Default Value 默认值

Description 说明

routesDirectory 路由目录

src/main/resources

To watch the directory for file changes which triggers a live reload of the Camel routes on-the-fly.
监视目录中的文件变化,从而触发 Camel 路由的实时重新加载。

duration 会期

-1

Sets the time duration (seconds) that the application will run for before terminating. A value ⇐ 0 will run forever.
设置应用程序在终止前运行的持续时间(秒)。值 ⇐ 0 将永远运行。

durationIdle 闲置时间

-1

Sets the idle time duration (seconds) duration that the application can be idle before terminating. A value ⇐ 0 will run forever.
设置应用程序终止前的空闲持续时间(秒)。值 ⇐ 0 将永远运行。

durationMaxMessages 最大持续时间

-1

Sets the duration of maximum number of messages that the application will process before terminating.
设置应用程序在终止前处理信息的最大数量。

logClasspath 日志路径

false 错误

Whether to log the classpath when starting
是否在启动

loggingLevel 日志级别

OFF

Whether to use built-in console logging (uses log4j), which does not require to add any logging dependency to your project. However, the logging is fixed to log to the console, with a color style that is similar to Spring Boot. You can change the root logging level to: FATAL, ERROR, WARN, INFO, DEBUG, TRACE, OFF
是否使用内置控制台日志(使用 log4j),这不需要在项目中添加任何日志依赖关系。不过,日志会固定记录到控制台,颜色风格与 Spring Boot 相似。你可以将根日志级别更改为致命、错误、警告、信息、调试、跟踪、关闭

profile 概况

dev 设计

To run with a specific Camel Main profile (dev,test,prod)
使用特定的 Camel 主配置文件(dev、test、prod)运行

camel:debug

The camel:debug is an extension to camel:dev to run the Camel application in debug mode which allows to debug the Camel routes thanks to the Camel textual route debugger.
camel:debugcamel:dev 的扩展,用于在调试模式下运行 Camel 应用程序,通过 Camel 文本路由调试器,可以调试 Camel 路由。

Options 选项

The maven plugin debug goal supports the following options which can be configured from the command line (use -D syntax), or defined in the pom.xml file in the <configuration> tag.
maven 插件调试目标支持以下选项,这些选项可通过命令行配置(使用 -D 语法),或在 pom.xml 文件的 <configuration> 标记中定义。

Parameter 参数

Default Value 默认值

Description 说明

suspend 吊销

true 

Indicates whether the message processing done by Camel should be suspended as long as a debugger is not attached.
指示只要未连接调试器,是否应暂停 Camel 的消息处理。

camel:prepare-fatjar

The camel:prepare-fatjar goal of the Camel Maven Plugin is used to prepare your Camel application for being packaged as a fat jar. The goal scans the Maven dependencies to discover Camel JARs and extract if they have type converters, which gets merged together into a single uber file stored in target/classes/META-INF/services/org/apache/camel/UberTypeConverterLoader.
Camel Maven 插件的 camel:prepare-fatjar 目标用于准备将 Camel 应用程序打包为胖 jar。该目标会扫描 Maven 依赖项以发现 Camel JAR,并提取其中是否有类型转换器,然后将其合并为一个 uber 文件,存储在 target/classes/META-INF/services/org/apache/camel/UberTypeConverterLoader 中。

This uber loader file contains all the combined type converters the Camel application uses at runtime. They are merged together into this single file.
该 uber 载入器文件包含 Camel 应用程序在运行时使用的所有组合类型转换器。它们被合并到这个单一文件中。

This is needed as otherwise the fat jar maven plugins (such as maven-assembly-plugin, or maven-shade-plugin) causes the TypeConverterLoader files to be overwritten in the assembled JAR which causes not all type converters to be loaded by Camel.
这是必要的,否则胖 jar maven 插件(如 maven-assembly-plugin 或 maven-shade-plugin)会导致 TypeConverterLoader 文件在组装的 JAR 中被覆盖,从而导致 Camel 无法加载所有类型转换器。

The UberTypeConverterLoader ensures they all type converters gets loaded as this file contains all the known type converter files.
UberTypeConverterLoader 可确保加载所有类型转换器,因为该文件包含所有已知的类型转换器文件。

To use this goal, you can add the following to your Camel application pom.xml file:
要使用此目标,您可以在 Camel 应用程序 pom.xml 文件中添加以下内容:

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-maven-plugin</artifactId>
        <version>${camel.version}</version>
        <executions>
          <execution>
            <goals>
              <goal>prepare-fatjar</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

For example to use this with the maven-assembly-plugin you can do as below. Remember to specify the class name of your main class where it says com.foo.NameOfMainClass:
例如,要在 maven-assembly-plugin 中使用此功能,可按以下步骤操作。记住要在 com.foo.NameOfMainClass 处指定主类的类名:

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-maven-plugin</artifactId>
        <version>${camel.version}</version>
        <executions>
          <execution>
            <goals>
              <goal>prepare-fatjar</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-assembly-plugin</artifactId>
        <configuration>
          <archive>
            <manifest>
              <mainClass>com.foo.NameOfMainClass</mainClass>
            </manifest>
          </archive>
        </configuration>
      </plugin>
    </plugins>
  </build>