Maven Archetypes
Introduction
A Maven archetype is a toolkit that defines a Maven project’s template. Maven archetypes provide Java developers the means to generate parameterized versions of the project’s template in a standardized manner.
Catalyst provides pre-defined Maven archetypes to create Serverless functions of the types Basic I/O and Advanced I/O. These archetypes will be listed from the Maven Central Repository. With these archetypes, you can simply provide input values containing the function details, and they will create and initialize the function in the standard structure and include the required dependencies in the Maven project’s directory. You can add multiple functions this way in individual POM directories.
You must remember the following points about creating functions with the Maven archetypes:
-
When you initialize a function from the CLI, you will be required to initialize the project first or add the function in an existing Catalyst project directory. In the case of Maven, you will not be able to initialize a project separately. You can directly create the function.
-
The function you create with an archetype will be created in the destination folder you select, as explained in the next section.
-
You can associate a function you create with the archetype with an existing project from your remote account by configuring its Project ID in the pom.xml Maven configuration file which is discussed in a later section. You will also need to add the Org ID of your Catalyst organization in this file.
-
You will not be able to create functions of any other type besides Basic I/O and Advanced I/O, or of any other stack, or the client component through the Maven tools. You will need to utilize the CLI to initialize these resources in your local environment.
Create a Basic I/O or an Advanced I/O Function with the Archetypes
In this help document, we cover the steps of working with the Catalyst Maven tools using the example of VS Code IDE. Some details may vary based on the IDE you use.
You can create a Basic I/O or an Advanced I/O function in the following way:
-
Create a new Maven project in your IDE. Depending on the IDE you use, the steps might vary. You can also convert an existing project to Maven, based on your IDE.
For VS Code, click the + icon under Maven to create a new Maven project.
- Type in “com.zoho.catalyst” in the archetype search bar. Select one of the following based on the type of function you want to create:
- catalyst-archetype-basicio: To create a Basic I/O function
- catalyst-archetype-advancedio: To create an Advanced I/O function with Catalyst SDK
- catalyst-archetype-advancedio-basic: To create an Advanced I/O function without Catalyst SDK
- Select the version of the archetype you choose. It is recommended to select the latest version.
- Enter a group ID for the project. This ID uniquely identifies your Maven project. You can press Enter to fill it with the default value.
- Enter an artifact ID for the project. This is the name of the JAR without version. You can press Enter to fill it with the default value.
-
Select a destination folder to save your Maven project.
-
You will be prompted for some inputs in the terminal. Press Enter after each input. You can also directly press Enter without an input to submit the default value.
- Version of the output JAR file’s SNAPSHOT
- Maven Package name
- The appName or the Catalyst reference name of the Java function
- Main class name of the function
- The project ID of the project this function will be associated with
- The org ID of your Catalyst organization that the project belongs to
- Confirm the properties configuration of your Maven project by entering “Y” and pressing Enter.
The function will be created in your Maven project with the directory structure as shown below.
When you intialize a Java function from the CLI, the function gets created with the catalyst.json project configuration file in the project’s root, the Catalyst Java SDK JAR files in the function’s root, as well as with other project dependencies. Creating a function using a Catalyst Maven archetype will not include the Java SDK files or any of the project dependencies in these directories.
The function’s directory will instead contain the source and target directories separately, and in addition, will also include pom.xml specific to the Maven environment. The main Java function file will also be created with the default code based on the function type, and the catalyst-config.json file will be created and auto-configured.
Last Updated 2024-04-15 17:30:30 +0530 +0530
Yes
No
Send your feedback to us