搜索

85.2. 编译

download PDF

csimple 语言被解析为常规 Java 源代码,并与所有其他源代码一起编译,或者在通过 camel-csimple-joor 模块 bootstrap 期间编译一次。

编译 csimple 有两种方法

  • 在构建时使用 camel-csimple-maven-plugin 生成源代码。
  • 使用 camel-csimple-joor,在 Camel 引导过程中执行运行时内存编译。

85.2.1. 使用 camel-csimple-maven-plugin

camel-csimple-maven-plugin Maven 插件用于从源代码发现所有 csimple 脚本,然后在 src/generated/java 文件夹中自动生成源代码,然后与所有其他源一起编译。

maven 插件将对 .java.xml 文件(Java 和 XML DSL)进行源代码扫描。扫描程序限制用于检测某些代码模式,如果它们以不常/垃圾的方式使用,则可能会取消发现一些 csimple 脚本。

使用 camel-csimple-joor 的运行时编译没有这个限制。

优点是,所有 csimple 脚本将使用常规 Java 编译器编译,因此所有都作为应用程序 JAR 文件中的 .class 文件包含在方框中,在运行时不需要额外的依赖项。

要使用 camel-csimple-maven-plugin,您需要将其添加到 pom.xml 文件中,如下所示:

<plugins>
    <!-- generate source code for csimple languages -->
    <plugin>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-csimple-maven-plugin</artifactId>
        <version>${camel.version}</version>
        <executions>
            <execution>
                <id>generate</id>
                <goals>
                    <goal>generate</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
    <!-- include source code generated to maven sources paths -->
    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>3.1.0</version>
        <executions>
            <execution>
                <phase>generate-sources</phase>
                <goals>
                    <goal>add-source</goal>
                    <goal>add-resource</goal>
                </goals>
                <configuration>
                    <sources>
                        <source>src/generated/java</source>
                    </sources>
                    <resources>
                        <resource>
                            <directory>src/generated/resources</directory>
                        </resource>
                    </resources>
                </configuration>
            </execution>
        </executions>
    </plugin>
</plugins>

然后,您还必须添加 build-helper-maven-plugin Maven 插件,以将 src/generated 包含在 Java 编译器的源文件夹列表中,以确保编译生成的源代码并包含在应用程序 JAR 文件中。

请参阅 Camel Examples 中的 camel-example-csimple 示例,它使用 maven 插件。

85.2.2. 使用 camel-csimple-joor

jOOR 库与 Java 编译器集成,并执行 Java 代码的运行时编译。

使用 camel-simple-joor 时支持的运行时适用于 Java 独立、Spring Boot、Camel Quarkus 和其他微服务运行时。这个功能在 Ice、Camel Swarm 或任何类型的 Java Application Server 运行时不支持。

joor 不支持使用 fat jar 打包的 Spring Boot 的运行时编译(https://github.com/jOOQ/jOOR/issues/69),它可用于探索的类路径。

要使用 camel-simple-joor,只需将其作为依赖项添加到 classpath 中:

<dependency>
  <groupId>org.apache.camel</groupId>
  <artifactId>camel-csimple-joor</artifactId>
  <version>{CamelSBProjectVersion}</version>
</dependency>

不需要将 Maven 插件添加到 pom.xml 文件中。

请参阅 camel-example-csimple-joor 示例(Camel Examples),它使用 jOOR 编译器。

Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.