Chapter 55. Getting Started with the Framework
55.1. Generate Code with the Maven Archetype
The API component Maven archetype
camel-archetype-api-component, that can generate starting point code for your own API component implementation. This is the recommended approach to start creating your own API component.
camel-archetype-api-componentarchetype are that Apache Maven is installed and the Maven
settings.xmlfile is configured to use the standard JBoss Fuse repositories. For more details, see appendix "Red Hat JBoss A-MQ Maven Repositories" in "Installation on Apache Karaf".
Invoke the Maven archetype
Examplecomponent, which uses the
exampleURI scheme, invoke the
camel-archetype-api-componentarchetype to generate a new Maven project, as follows:
mvn archetype:generate \ -DarchetypeGroupId=org.apache.camel.archetypes \ -DarchetypeArtifactId=camel-archetype-api-component \ -DarchetypeVersion=2.17.0.redhat-630xxx \ -DgroupId=org.jboss.fuse.example \ -DartifactId=camel-api-example \ -Dname=Example \ -Dscheme=example \ -Dversion=1.0-SNAPSHOT \ -DinteractiveMode=false
\, at the end of each line represents line continuation, which works only on Linux and UNIX platforms. On Windows platforms, remove the backslash and put the arguments all on a single line.
-DName=Value. Most of the options should be set as shown in the preceding
mvn archetype:generatecommand, but a few of the options can be modified, to customize the generated project. The following table shows the options that you can use to customize the generated API component project:
|(Generic Maven option) Specifies the group ID of the generated Maven project. By default, this value also defines the Java package name for the generated classes. Hence, it is a good idea to choose this value to match the Java package name that you want.|
|(Generic Maven option) Specifies the artifact ID of the generated Maven project.|
|The name of the API component. This value is used for generating class names in the generated code (hence, it is recommended that the name should start with a capital letter).|
|The default scheme to use in URIs for this component. You should make sure that this scheme does not conflict with the scheme of any existing Camel components.|
|(Generic Maven option) Ideally, this should be the Apache Camel version used by the container where you plan to deploy the component. If necessary, however, you can also modify the versions of Maven dependencies after you have generated the project.|
Structure of the generated project
camel-api-example, which contains the new Maven project. If you look inside the
camel-api-exampledirectory, you will see that it has the following general structure:
camel-api-example/ pom.xml camel-api-example-api/ camel-api-example-component/
pom.xml, which is configured to build two sub-projects, as follows:
- The API sub-project (named as
ArtifactId-api) holds the Java API which you are about to turn into a component. If you are basing the API component on a Java API that you wrote yourself, you can put the Java API code directly into this project.The API sub-project can be used for one or more of the following purposes:
In some cases, however, you might not need to perform any of these tasks. For example, if the API component is based on a third-party API, which already provides the Java API and Javadoc in a Maven package. In such cases, you can delete the API sub-project.
- To package up the Java API code (if it is not already available as a Maven package).
- To generate Javadoc for the Java API (providing the needed metadata for the API component framework).
- To generate the Java API code from an API description (for example, from a WADL description of a REST API).
- The component sub-project (named as
ArtifactId-component) holds the implementation of the new API component. This includes the component implementation classes and the configuration of the
camel-api-component-mavenplug-in (which generates the API mapping classes from the Java API).