天天看点

使用camel-component-maven-plugin生成camel的配置类和元数据信息参考

使用camel-component-maven-plugin生成camel的配置类和元数据信息

  • 参考

利用camel-component-maven-plugin可以方便第三方组件开发,通过该组件可以生成用于Camel3.x配置的元数据和相关Java类。

如果希望该插件正常工作,需要在开发组件时添加必要的注解。如,为你的Componet类添加@Component注解,为你的endpoint类添加@Endpoint注解,以及@UriParams等。

可以通过查看现有组件实现来了解各注解的使用方法,或者通过Camel Maven Archetypes来初始化组件。

要利用插件需要引入pom配置:

<plugin>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-component-maven-plugin</artifactId>
    <version>${camel.version}</version>
    <executions>
        <execution>
            <id>generate</id>
            <goals>
                <goal>generate</goal>
            </goals>
            <phase>process-classes</phase>
        </execution>
    </executions>
</plugin>
           

可以通过执行mvn test, mvn package, mvn test, mvn install等命令触发插件执行。

生成的metedata和java类默认路径是 src/generated/java 和 src/generated/resources,如果希望在打包时包含这些文件,需要添加额外的maven配置。

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <executions>
        <execution>
            <phase>initialize</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>
           

参考

CAMEL COMPONENT MAVEN PLUGIN