Menu Close
Settings Close

Language and Page Formatting Options

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 ed­i­tor or IDE is available.
  • Curl or HTTPie or a browser to per­form HTTP re­quests is available.

Procedure

  1. 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
  2. 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.
  3. Create a directory and go to the directory location.

    mkdir getting-started && cd getting-started
  4. 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:

    AttributeDefault ValueDescription

    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 de­scrip­tor pom.xml con­fig­ured to build and run your ap­pli­ca­tion
    • Example verticle in the src/main/java folder
  5. 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.

  6. Use the Eclipse Vert.x project as a template to create your own application.
  7. Build the application using Maven from the root directory of the application.

    mvn package
  8. 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 ed­i­tor or IDE is available.
  • Curl or HTTPie or a browser to per­form HTTP re­quests is available.

Procedure

  1. 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
  2. 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.
  3. Go to Vert.x Starter.
  4. Select the Version of Eclipse Vert.x.
  5. Select Java as the language.
  6. Select Maven as the build tool.
  7. Enter a Group Id, which is a unique identifier of your project. For this procedure, keep the default, com.example.
  8. Enter an Artifact Id, which is the name of your project and your project directory. For this procedure, keep the default, starter.
  9. Specify the dependencies you want to add to your project. For this procedure, add Vert.x Web de­pen­dency either by typing it in the De­pen­den­cies text box or select from the list of De­pen­den­cies.
  10. Click Advanced options to select the OpenJDK version. For this procedure, keep the default, JDK 11.
  11. Click Gen­er­ate Project. The starter.zip file containing the artifacts for Eclipse Vert.x project is downloaded.
  12. Create a directory getting-started.
  13. 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 de­scrip­tor pom.xml file. The file has configurations to build and run your ap­pli­ca­tion.
    • Example verticle in the src/main/java folder.
    • Sam­ple test using JUnit 5 in the src/test/java folder.
    • Ed­i­tor con­fig­u­ra­tion to en­force code style.
    • Git con­fig­u­ra­tion to ig­nore files.
  14. 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 with vertx-dependencies.
  15. 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.

  16. Use the Eclipse Vert.x project as a template to create your own application.
  17. Build the application using Maven from the root directory of the application.

    mvn package
  18. Run the application using Maven from the root directory of the application.

    mvn exec:java
  19. Verify that the application is running.

    Use curl or your browser to verify if your application is running at http://localhost:8888 and returns "Hello from Vert.x!" as response.

    $ curl http://localhost:8888
    Hello from Vert.x!