Chapter 5. Other ways to create Eclipse Vert.x projects
This section shows the different ways in which you can create Eclipse Vert.x projects.
5.1. Creating a Eclipse Vert.x project on the command line
You can use the Eclipse Vert.x Maven plug-in on the command line to create a Eclipse Vert.x project. You can specify the attributes and values on the command line.
Prerequisites
- OpenJDK 8 or OpenJDK 11 is installed.
- Maven 3 or higher is installed.
- A text editor or IDE is available.
- Curl or HTTPie or a browser to perform HTTP requests is available.
Procedure
In a command terminal, enter the following command to verify that Maven is using OpenJDK 8 or OpenJDK 11 and the Maven version is 3.6.0 or higher:
mvn --version
- If the preceding command does not return OpenJDK 8 or OpenJDK 11, add the path to OpenJDK 8 or OpenJDK 11 to the PATH environment variable and enter the command again.
Create a directory and go to the directory location.
mkdir getting-started && cd getting-started
Use the following command to create a new project using the Eclipse Vert.x Maven plug-in.
mvn io.reactiverse:vertx-maven-plugin:${vertx-maven-plugin-version}:setup -DvertxBom=vertx-dependencies \ -DvertxVersion=${vertx_version} \ -DprojectGroupId= ${project_group_id} \ -DprojectArtifactId= ${project_artifact_id} \ -DprojectVersion=${project-version} \ -Dverticle=${verticle_class} \ -Ddependencies=${dependency_names}
The following example shows you how you can create an Eclipse Vert.x application using the command explained.
mvn io.reactiverse:vertx-maven-plugin:1.0.24:setup -DvertxBom=vertx-dependencies \ -DvertxVersion=4.1.8.redhat-00003 \ -DprojectGroupId=io.vertx.myapp \ -DprojectArtifactId=my-new-project \ -DprojectVersion=1.0-SNAPSHOT \ -DvertxVersion=4.1.8.redhat-00003 \ -Dverticle=io.vertx.myapp.MainVerticle \ -Ddependencies=web
The following table lists the attributes that you can define with the
setup
command:Attribute Default Value Description vertx_version
The version of Eclipse Vert.x.
The version of Eclipse Vert.x you want to use in your project.
project_group_id
io.vertx.example
A unique identifier of your project.
project_artifact_id
my-vertx-project
The name of your project and your project directory. If you do not specify the
project_artifact_id
, the Maven plug-in starts the interactive mode. If the directory already exists, the generation fails.project-version
1.0-SNAPSHOT
The version of your project.
verticle_class
io.vertx.example.MainVerticle
The new verticle class file created by the verticle parameter.
dependency_names
Optional parameter
The list of dependencies you want to add to your project separated by comma. You can also use the following syntax to configure the dependencies:
groupId:artifactId:version:classifier
For example:
- To inherit the version from BOM use the following syntax:
io.vertx:vertxcodetrans
- To specify dependency use the following syntax:
commons-io:commons-io:2.5
- To specify dependency with a classifier use the following syntax:
io.vertx:vertx-template-engines:3.4.1:shaded
The command creates an empty Eclipse Vert.x project with the following artifacts in the
getting-started
directory:-
The Maven build descriptor
pom.xml
configured to build and run your application -
Example verticle in the
src/main/java
folder
-
The Maven build descriptor
In the
pom.xml
file, specify the repositories that contain the Eclipse Vert.x artifacts to build your application.<repositories> <repository> <id>redhat-ga</id> <name>Red Hat GA Repository</name> <url>https://maven.repository.redhat.com/ga/</url> </repository> </repositories>
Alternatively, you can configure the Maven repository to specify the build artifacts in the
settings.xml
file. See the section Configuring the Apache Maven repository for your Eclipse Vert.x projects, for more information.- Use the Eclipse Vert.x project as a template to create your own application.
Build the application using Maven from the root directory of the application.
mvn package
Run the application using Maven from the root directory of the application.
mvn vertx:run
5.2. Creating a Eclipse Vert.x project using the community Vert.x starter
You can use the community Vert.x starter to create a Eclipse Vert.x project. The starter creates a community project. You will have to convert the community project to a Red Hat build of Eclipse Vert.x project.
Prerequisites
- OpenJDK 8 or OpenJDK 11 is installed.
- Maven 3 or higher is installed.
- A text editor or IDE is available.
- Curl or HTTPie or a browser to perform HTTP requests is available.
Procedure
In a command terminal, enter the following command to verify that Maven is using OpenJDK 8 or OpenJDK 11 and the Maven version is 3.6.0 or higher:
mvn --version
- If the preceding command does not return OpenJDK 8 or OpenJDK 11, add the path to OpenJDK 8 or OpenJDK 11 to the PATH environment variable and enter the command again.
- Go to Vert.x Starter.
- Select the Version of Eclipse Vert.x.
- Select Java as the language.
- Select Maven as the build tool.
- Enter a Group Id, which is a unique identifier of your project. For this procedure, keep the default, com.example.
- Enter an Artifact Id, which is the name of your project and your project directory. For this procedure, keep the default, starter.
- Specify the dependencies you want to add to your project. For this procedure, add Vert.x Web dependency either by typing it in the Dependencies text box or select from the list of Dependencies.
- Click Advanced options to select the OpenJDK version. For this procedure, keep the default, JDK 11.
-
Click Generate Project. The
starter.zip
file containing the artifacts for Eclipse Vert.x project is downloaded. -
Create a directory
getting-started
. Extract the contents of the ZIP file to the
getting-started
folder. The Vert.x Starter creates an Eclipse Vert.x project with the following artifacts:-
Maven build descriptor
pom.xml
file. The file has configurations to build and run your application. -
Example verticle in the
src/main/java
folder. -
Sample test using JUnit 5 in the
src/test/java
folder. - Editor configuration to enforce code style.
- Git configuration to ignore files.
-
Maven build descriptor
To convert the community project to a Red Hat build of Eclipse Vert.x project, replace the following values in
pom.xml
file:-
vertx.version
- Specify the Eclipse Vert.x version you want to use. For example, if you want to use Eclipse Vert.x 4.1.8 version, specify the version as 4.1.8.redhat-00003. -
vertx-stack-depchain
- Replace this dependency withvertx-dependencies
.
-
Specify the repositories that contain the Eclipse Vert.x artifacts to build your application in the
pom.xml
file.<repositories> <repository> <id>redhat-ga</id> <name>Red Hat GA Repository</name> <url>https://maven.repository.redhat.com/ga/</url> </repository> </repositories>
Alternatively, you can configure the Maven repository to specify the build artifacts in the
settings.xml
file. See the section Configuring the Apache Maven repository for your Eclipse Vert.x projects, for more information.- Use the Eclipse Vert.x project as a template to create your own application.
Build the application using Maven from the root directory of the application.
mvn package
Run the application using Maven from the root directory of the application.
mvn exec:java
Verify that the application is running.
Use
curl
or your browser to verify if your application is running athttp://localhost:8888
and returns "Hello from Vert.x!" as response.$ curl http://localhost:8888 Hello from Vert.x!