此内容没有您所选择的语言版本。
Chapter 3. Creating an Eclipse Vert.x project with a POM file
When you develop a basic Eclipse Vert.x application, you should create the following artifacts. We will create these artifacts in our first getting-started Eclipse Vert.x project.
- A Java class containing Eclipse Vert.x methods.
-
A
pom.xmlfile containing information required by Maven to build the application.
The following procedure creates a simple Greeting application that returns Greetings! as response.
Eclipse Vert.x supports builder images based on OpenJDK 8 and OpenJDK 11 for building and deploying your applications to OpenShift. Oracle JDK and OpenJDK 9 builder images are not supported.
Prerequisites
- OpenJDK 8 or OpenJDK 11 is installed.
- Maven is installed.
Procedure
Create a new directory
getting-started, and navigate to it.mkdir getting-started cd getting-started
$ mkdir getting-started $ cd getting-startedCopy to Clipboard Copied! Toggle word wrap Toggle overflow This is the root directory for the application.
Create a directory structure
src/main/java/com/example/in the root directory, and navigate to it.mkdir -p src/main/java/com/example/ cd src/main/java/com/example/
$ mkdir -p src/main/java/com/example/ $ cd src/main/java/com/example/Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create a Java class file
MyApp.javacontaining the application code.Copy to Clipboard Copied! Toggle word wrap Toggle overflow The application starts an HTTP Server on port 8080. When you send a request, it returns Greetings! message.
Create a
pom.xmlfile in the application root directorygetting-startedwith the following content:-
In the
<dependencyManagement>section, add theio.vertx:vertx-dependenciesartifact. -
Specify the
typeaspomandscopeasimport. In the
<project>section, under<properties>, specify the versions of Eclipse Vert.x and the Eclipse Vert.x Maven Plugin.NoteProperties can be used to set values that change in every release. For example, versions of product or plugins.
-
In the
<project>section, under<plugin>, specifyvertx-maven-plugin. The Eclipse Vert.x Maven Plugin is used to package your application. Include
repositoriesandpluginRepositoriesto specify the repositories that contain the artifacts and plugins to build your application.The
pom.xmlcontains the following artifacts:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
In the
Build the application using Maven from the root directory of the application.
mvn vertx:run
mvn vertx:runCopy to Clipboard Copied! Toggle word wrap Toggle overflow Verify that the application is running.
Use
curlor your browser to verify if your application is running athttp://localhost:8080and returns "Greetings!" as response.curl http://localhost:8080
$ curl http://localhost:8080 Greetings!Copy to Clipboard Copied! Toggle word wrap Toggle overflow