Chapter 3. Developing and deploying Eclipse Vert.x runtime application You can create a new Eclipse Vert.x application and deploy it to OpenShift or stand-alone Red Hat Enterprise Linux. 3.1. Developing Eclipse Vert.x application For a basic Eclipse Vert.x application, you need to create the following: A Java class containing Eclipse Vert.x methods. A pom.xml file containing information required by Maven to build the application. The following procedure creates a simple Greeting application that returns "Greetings!" as response. Note For building and deploying your applications to OpenShift, Eclipse Vert.x 4.3 only supports builder images based on OpenJDK 8 and OpenJDK 11. Oracle JDK and OpenJDK 9 builder images are not supported. Prerequisites OpenJDK 8 or OpenJDK 11 installed. Maven installed. Procedure Create a new directory myApp , and navigate to it. USD mkdir myApp USD cd myApp This is the root directory for the application. Create directory structure src/main/java/com/example/ in the root directory, and navigate to it. USD mkdir -p src/main/java/com/example/ USD cd src/main/java/com/example/ Create a Java class file MyApp.java containing the application code. package com.example; import io.vertx.core.AbstractVerticle; import io.vertx.core.Promise; public class MyApp extends AbstractVerticle { @Override public void start(Promise<Void> promise) { vertx .createHttpServer() .requestHandler(r -> r.response().end("Greetings!")) .listen(8080, result -> { if (result.succeeded()) { promise.complete(); } else { promise.fail(result.cause()); } }); } } Create a pom.xml file in the application root directory myApp with the following content: <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <artifactId>my-app</artifactId> <version>1.0.0-SNAPSHOT</version> <packaging>jar</packaging> <name>My Application</name> <description>Example application using Vert.x</description> <properties> <vertx.version>4.3.7.redhat-00002</vertx.version> <vertx-maven-plugin.version>1.0.24</vertx-maven-plugin.version> <vertx.verticle>com.example.MyApp</vertx.verticle> <!-- Specify the JDK builder image used to build your application. --> <jkube.generator.from>registry.access.redhat.com/ubi8/openjdk-11</jkube.generator.from> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> </properties> <!-- Import dependencies from the Vert.x BOM. --> <dependencyManagement> <dependencies> <dependency> <groupId>io.vertx</groupId> <artifactId>vertx-dependencies</artifactId> <version>USD{vertx.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <!-- Specify the Vert.x artifacts that your application depends on. --> <dependencies> <dependency> <groupId>io.vertx</groupId> <artifactId>vertx-core</artifactId> </dependency> <dependency> <groupId>io.vertx</groupId> <artifactId>vertx-web</artifactId> </dependency> </dependencies> <!-- Specify the repositories containing Vert.x artifacts. --> <repositories> <repository> <id>redhat-ga</id> <name>Red Hat GA Repository</name> <url>https://maven.repository.redhat.com/ga/</url> </repository> </repositories> <!-- Specify the repositories containing the plugins used to execute the build of your application. --> <pluginRepositories> <pluginRepository> <id>redhat-ga</id> <name>Red Hat GA Repository</name> <url>https://maven.repository.redhat.com/ga/</url> </pluginRepository> </pluginRepositories> <!-- Configure your application to be packaged using the Vert.x Maven Plugin. --> <build> <plugins> <plugin> <groupId>io.reactiverse</groupId> <artifactId>vertx-maven-plugin</artifactId> <version>USD{vertx-maven-plugin.version}</version> <executions> <execution> <id>vmp</id> <goals> <goal>initialize</goal> <goal>package</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project> Build the application using Maven from the root directory of the application. USD mvn vertx:run Verify that the application is running. Using curl or your browser, verify your application is running at http://localhost:8080 . USD curl http://localhost:8080 Greetings! Additional information As a recommended practice, you can configure liveness and readiness probes to enable health monitoring for your application when running on OpenShift. 3.2. Deploying Eclipse Vert.x application to OpenShift To deploy your Eclipse Vert.x application to OpenShift, configure the pom.xml file in your application and then use the OpenShift Maven plugin. Note The Fabric8 Maven plugin is no longer supported. Use the OpenShift Maven plugin to deploy your Eclipse Vert.x applications on OpenShift. For more information, see the section migrating from Fabric8 Maven Plugin to Eclipse JKube . You can specify a Java image by replacing the jkube.generator.from URL in the pom.xml file. The images are available in the Red Hat Ecosystem Catalog . For example, the Java image for RHEL 7 with OpenJDK 8 is specified as: 3.2.1. Supported Java images for Eclipse Vert.x Eclipse Vert.x is certified and tested with various Java images that are available for different operating systems. For example, Java images are available for RHEL 7 with OpenJDK 8 or OpenJDK 11. Eclipse Vert.x introduces support for building and deploying Eclipse Vert.x applications to OpenShift with OCI-compliant Universal Base Images for Red Hat OpenJDK 8 and Red Hat OpenJDK 11 on RHEL 8. You require Docker or podman authentication to access the RHEL 8 images in the Red Hat Ecosystem Catalog. The following table lists the container images supported by Eclipse Vert.x for different architectures. These container images are available in the Red Hat Ecosystem Catalog . In the catalog, you can search and download the images listed in the table below. The image pages contain authentication procedures required to access the images. Table 3.1. OpenJDK images and architectures JDK (OS) Architecture supported Images available in Red Hat Ecosystem Catalog OpenJDK8 (RHEL 7) x86_64 redhat-openjdk-18/openjdk18-openshift OpenJDK11 (RHEL 7) x86_64 openjdk/openjdk-11-rhel7 OpenJDK8 (RHEL 8) x86_64 ubi8/openjdk-8-runtime OpenJDK11 (RHEL 8) x86_64, IBM Z, and IBM Power Systems ubi8/openjdk-11 Note The use of a RHEL 8-based container on a RHEL 7 host, for example with OpenShift 3 or OpenShift 4, has limited support. For more information, see the Red Hat Enterprise Linux Container Compatibility Matrix . 3.2.2. Preparing Eclipse Vert.x application for OpenShift deployment For deploying your Eclipse Vert.x application to OpenShift, it must contain: Launcher profile information in the application's pom.xml file. In the following procedure, a profile with OpenShift Maven plugin is used for building and deploying the application to OpenShift. Prerequisites Maven is installed. Docker or podman authentication into Red Hat Ecosystem Catalog to access RHEL 8 images. Procedure Add the following content to the pom.xml file in the application root directory: <!-- Specify the JDK builder image used to build your application. --> <properties> <jkube.generator.from>registry.access.redhat.com/redhat-openjdk-18/openjdk18-openshift:latest</jkube.generator.from> </properties> ... <profiles> <profile> <id>openshift</id> <build> <plugins> <plugin> <groupId>org.eclipse.jkube</groupId> <artifactId>openshift-maven-plugin</artifactId> <version>1.1.1</version> <executions> <execution> <goals> <goal>resource</goal> <goal>build</goal> <goal>apply</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </profile> </profiles> Replace the jkube.generator.from property in the pom.xml file to specify the OpenJDK image that you want to use. x86_64 architecture RHEL 7 with OpenJDK 8 <jkube.generator.from>registry.access.redhat.com/redhat-openjdk-18/openjdk18-openshift:latest</jkube.generator.from> RHEL 7 with OpenJDK 11 <jkube.generator.from>registry.access.redhat.com/openjdk/openjdk-11-rhel7:latest</jkube.generator.from> RHEL 8 with OpenJDK 8 <jkube.generator.from>registry.access.redhat.com/ubi8/openjdk-8:latest</jkube.generator.from> x86_64, s390x (IBM Z), and ppc64le (IBM Power Systems) architectures RHEL 8 with OpenJDK 11 <jkube.generator.from>registry.access.redhat.com/ubi8/openjdk-11:latest</jkube.generator.from> 3.2.3. Deploying Eclipse Vert.x application to OpenShift using OpenShift Maven plugin To deploy your Eclipse Vert.x application to OpenShift, you must perform the following: Log in to your OpenShift instance. Deploy the application to the OpenShift instance. Prerequisites oc CLI client installed. Maven installed. Procedure Log in to your OpenShift instance with the oc client. USD oc login ... Create a new project in the OpenShift instance. USD oc new-project MY_PROJECT_NAME Deploy the application to OpenShift using Maven from the application's root directory. The root directory of an application contains the pom.xml file. USD mvn clean oc:deploy -Popenshift This command uses the OpenShift Maven plugin to launch the S2I process on OpenShift and start the pod. Verify the deployment. Check the status of your application and ensure your pod is running. USD oc get pods -w NAME READY STATUS RESTARTS AGE MY_APP_NAME-1-aaaaa 1/1 Running 0 58s MY_APP_NAME-s2i-1-build 0/1 Completed 0 2m The MY_APP_NAME-1-aaaaa pod should have a status of Running once it is fully deployed and started. Your specific pod name will vary. Determine the route for the pod. Example Route Information USD oc get routes NAME HOST/PORT PATH SERVICES PORT TERMINATION MY_APP_NAME MY_APP_NAME-MY_PROJECT_NAME.OPENSHIFT_HOSTNAME MY_APP_NAME 8080 The route information of a pod gives you the base URL which you use to access it. In this example, http://MY_APP_NAME-MY_PROJECT_NAME.OPENSHIFT_HOSTNAME is the base URL to access the application. Verify that your application is running in OpenShift. USD curl http://MY_APP_NAME-MY_PROJECT_NAME.OPENSHIFT_HOSTNAME Greetings! 3.3. Deploying Eclipse Vert.x application to stand-alone Red Hat Enterprise Linux To deploy your Eclipse Vert.x application to stand-alone Red Hat Enterprise Linux, configure the pom.xml file in the application, package it using Maven and deploy using the java -jar command. Prerequisites RHEL 7 or RHEL 8 installed. 3.3.1. Preparing Eclipse Vert.x application for stand-alone Red Hat Enterprise Linux deployment For deploying your Eclipse Vert.x application to stand-alone Red Hat Enterprise Linux, you must first package the application using Maven. Prerequisites Maven installed. Procedure Add the following content to the pom.xml file in the application's root directory: ... <build> <plugins> <plugin> <groupId>io.reactiverse</groupId> <artifactId>vertx-maven-plugin</artifactId> <version>1.0.24</version> <executions> <execution> <id>vmp</id> <goals> <goal>initialize</goal> <goal>package</goal> </goals> </execution> </executions> </plugin> </plugins> </build> ... Package your application using Maven. USD mvn clean package The resulting JAR file is in the target directory. 3.3.2. Deploying Eclipse Vert.x application to stand-alone Red Hat Enterprise Linux using jar To deploy your Eclipse Vert.x application to stand-alone Red Hat Enterprise Linux, use java -jar command. Prerequisites RHEL 7 or RHEL 8 installed. OpenJDK 8 or OpenJDK 11 installed. A JAR file with the application. Procedure Deploy the JAR file with the application. USD java -jar my-app-fat.jar Verify the deployment. Use curl or your browser to verify your application is running at http://localhost:8080 : USD curl http://localhost:8080

Commands:
mkdir myApp cd myApp
mkdir -p src/main/java/com/example/ cd src/main/java/com/example/
package com.example; import io.vertx.core.AbstractVerticle; import io.vertx.core.Promise; public class MyApp extends AbstractVerticle { @Override public void start(Promise<Void> promise) { vertx .createHttpServer() .requestHandler(r -> r.response().end("Greetings!")) .listen(8080, result -> { if (result.succeeded()) { promise.complete(); } else { promise.fail(result.cause()); } }); } }
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <artifactId>my-app</artifactId> <version>1.0.0-SNAPSHOT</version> <packaging>jar</packaging> <name>My Application</name> <description>Example application using Vert.x</description> <properties> <vertx.version>4.3.7.redhat-00002</vertx.version> <vertx-maven-plugin.version>1.0.24</vertx-maven-plugin.version> <vertx.verticle>com.example.MyApp</vertx.verticle> <!-- Specify the JDK builder image used to build your application. --> <jkube.generator.from>registry.access.redhat.com/ubi8/openjdk-11</jkube.generator.from> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> </properties> <!-- Import dependencies from the Vert.x BOM. --> <dependencyManagement> <dependencies> <dependency> <groupId>io.vertx</groupId> <artifactId>vertx-dependencies</artifactId> <version>USD{vertx.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <!-- Specify the Vert.x artifacts that your application depends on. --> <dependencies> <dependency> <groupId>io.vertx</groupId> <artifactId>vertx-core</artifactId> </dependency> <dependency> <groupId>io.vertx</groupId> <artifactId>vertx-web</artifactId> </dependency> </dependencies> <!-- Specify the repositories containing Vert.x artifacts. --> <repositories> <repository> <id>redhat-ga</id> <name>Red Hat GA Repository</name> <url>https://maven.repository.redhat.com/ga/</url> </repository> </repositories> <!-- Specify the repositories containing the plugins used to execute the build of your application. --> <pluginRepositories> <pluginRepository> <id>redhat-ga</id> <name>Red Hat GA Repository</name> <url>https://maven.repository.redhat.com/ga/</url> </pluginRepository> </pluginRepositories> <!-- Configure your application to be packaged using the Vert.x Maven Plugin. --> <build> <plugins> <plugin> <groupId>io.reactiverse</groupId> <artifactId>vertx-maven-plugin</artifactId> <version>USD{vertx-maven-plugin.version}</version> <executions> <execution> <id>vmp</id> <goals> <goal>initialize</goal> <goal>package</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project>
mvn vertx:run
curl http://localhost:8080 Greetings!
<jkube.generator.from>IMAGE_NAME</jkube.generator.from>
<jkube.generator.from>registry.access.redhat.com/redhat-openjdk-18/openjdk18-openshift:latest</jkube.generator.from>
<!-- Specify the JDK builder image used to build your application. --> <properties> <jkube.generator.from>registry.access.redhat.com/redhat-openjdk-18/openjdk18-openshift:latest</jkube.generator.from> </properties> <profiles> <profile> <id>openshift</id> <build> <plugins> <plugin> <groupId>org.eclipse.jkube</groupId> <artifactId>openshift-maven-plugin</artifactId> <version>1.1.1</version> <executions> <execution> <goals> <goal>resource</goal> <goal>build</goal> <goal>apply</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </profile> </profiles>
<jkube.generator.from>registry.access.redhat.com/redhat-openjdk-18/openjdk18-openshift:latest</jkube.generator.from>
<jkube.generator.from>registry.access.redhat.com/openjdk/openjdk-11-rhel7:latest</jkube.generator.from>
<jkube.generator.from>registry.access.redhat.com/ubi8/openjdk-8:latest</jkube.generator.from>
<jkube.generator.from>registry.access.redhat.com/ubi8/openjdk-11:latest</jkube.generator.from>
oc login
oc new-project MY_PROJECT_NAME
mvn clean oc:deploy -Popenshift
oc get pods -w NAME READY STATUS RESTARTS AGE MY_APP_NAME-1-aaaaa 1/1 Running 0 58s MY_APP_NAME-s2i-1-build 0/1 Completed 0 2m
oc get routes NAME HOST/PORT PATH SERVICES PORT TERMINATION MY_APP_NAME MY_APP_NAME-MY_PROJECT_NAME.OPENSHIFT_HOSTNAME MY_APP_NAME 8080
curl http://MY_APP_NAME-MY_PROJECT_NAME.OPENSHIFT_HOSTNAME Greetings!
<build> <plugins> <plugin> <groupId>io.reactiverse</groupId> <artifactId>vertx-maven-plugin</artifactId> <version>1.0.24</version> <executions> <execution> <id>vmp</id> <goals> <goal>initialize</goal> <goal>package</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
mvn clean package
java -jar my-app-fat.jar
curl http://localhost:8080