第3章 Eclipse Vert.x ランタイムアプリケーションの開発およびデプロイ


Eclipse Vert.x アプリケーションを新規作成し、OpenShift またはスタンドアロンの Red Hat Enterprise Linux にデプロイできます。

3.1. Eclipse Vert.x アプリケーションの開発

基本的な Eclipse Vert.x アプリケーションには、以下を作成する必要があります。

  • Eclipse Vert.x メソッドを含む Java クラス。
  • アプリケーションをビルドするために Maven が必要とする情報が含まれる pom.xml ファイル。

以下の手順では、応答として Greetings! を返す単純な Greeting アプリケーションを作成します。

注記

アプリケーションをビルドおよび OpenShift にデプロイする場合、Eclipse Vert.x 4.2 は OpenJDK 8 および OpenJDK 11 をベースとしたビルダーイメージのみをサポートします。Oracle JDK および OpenJDK 9 のビルダーイメージはサポートされていません。

前提条件

  • OpenJDK 8 または OpenJDK 11 がインストールされている。
  • Maven がインストールされている。

手順

  1. 新しいディレクトリー myApp を作成し、そのディレクトリーに移動します。

    $ mkdir myApp
    $ cd myApp
    Copy to Clipboard

    これは、アプリケーションのルートディレクトリーです。

  2. ルートディレクトリーにディレクトリー構造 src/main/java/com/example/ を作成し、これに移動します。

    $ mkdir -p src/main/java/com/example/
    $ cd src/main/java/com/example/
    Copy to Clipboard
  3. アプリケーションコードを含む Java クラスファイル MyApp.java を作成します。

    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());
                    }
                });
        }
    }
    Copy to Clipboard
  4. 以下の内容を含むアプリケーションルートディレクトリー myApppom.xml ファイルを作成します。

    <?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.2.7.redhat-00003</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>${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>${vertx-maven-plugin.version}</version>
            <executions>
              <execution>
                <id>vmp</id>
                <goals>
                  <goal>initialize</goal>
                  <goal>package</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </project>
    Copy to Clipboard
  5. アプリケーションのルートディレクトリーから Maven を使用してアプリケーションをビルドします。

    $ mvn vertx:run
    Copy to Clipboard
  6. アプリケーションが実行していることを確認します。

    curl またはブラウザーを使用して、アプリケーションが http://localhost:8080 で稼働していることを確認します。

    $ curl http://localhost:8080
    Greetings!
    Copy to Clipboard

関連情報

  • 推奨されるプラクティスとして、liveness プローブおよび readiness プローブを設定し、OpenShift で実行する際にアプリケーションのヘルスモニターリングを有効にできます。
トップに戻る
Red Hat logoGithubredditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

Red Hat ドキュメントについて

Red Hat をお使いのお客様が、信頼できるコンテンツが含まれている製品やサービスを活用することで、イノベーションを行い、目標を達成できるようにします。 最新の更新を見る.

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

Theme

© 2025 Red Hat