This repository contains a range of examples so you can get up and running easily with Vert.x.
Start with the simplest Maven example to show you how setup a simple Vert.x project that uses Maven.
Use that as a template for setting up a Maven project with Vert.x.
Progress to the simple Maven verticle example to show you how to deploy your code as verticles in a Maven project.
Start with the simplest Gradle example to show you how setup a simple Vert.x project that uses Gradle.
Use that as a template for setting up a Maven project with Gradle.
Progress to the simple Gradle verticle example to show you how to deploy your code as verticles in a Gradle project
That’s fine too :)
You can run most of the examples at the command line using vertx run
if you have Vert.x installed (see below).
The examples demonstrate how to use all different bits of Vert.x including Vert.x core, Apex (webapps) and various other services and features.
Most of the examples have been written as verticles. For more information on verticles please consult the Vert.x core manual.
Using verticles allows you to scale and run your code from the command line more easily, but if you prefer to embed, the exact same code in the verticles can also be run embedded if you prefer. It’s really up to you. Verticles are entirely optional in Vert.x.
Most of the examples are available in all the languages that Vert.x supports.
You’ll find the examples for the relevant language in a directory src/main/${lang}
where lang
is an identifier for the
language, e.g. java
, js
, ruby
etc.
For example you’ll find the Vert.x core Java examples in core-examples/src/main/java and you’ll find the Vert.x core JavaScript examples in core-examples/src/main/js
Note
|
All the non-Java examples are automatically generated from the Java examples using our magic code translator. |
Most of the Java examples can be run directly in your IDE (if you have one!).
We provide a main()
method in most of the example classes which allows you to conveniently run them directly in your IDE.
Just right click the main method or class in your IDE and run as… application (supported by all major IDEs).
If vertx
is installed you can also run any verticle directly on the command line. This way of working may be of interest
to you if you don’t want to use Maven or Gradle or perhaps you don’t use an IDE.
Or perhaps you’re just a command line kind of person.
If you’re coming from using other platforms such as Node.js you might want to work this way. You can think of the
vertx
command as a bit like the node
command in Node.js.
Instructions for installing Vert.x are in the next section.
Once Vert.x is installed, to run an example, just cd to the example directory and type vertx run
followed by the filename
of the verticle. For example
cd core-examples/src/main/java/io/vertx/example/core vertx run EchoServer.java cd core-examples/src/main/js/echo vertx run echo_server.js
Yes! You can run Java source files directly using Vert.x (no compilation required) :)
Note
|
This is only necessary if you want to run Vert.x at the command line. If you’d prefer to work with Maven or Gradle projects then you don’t need to pre-install Vert.x - you just let Maven/Gradle pull in the Vert.x dependencies into your project as you would with any dependency. |
Pre-requisites: You will need to have Java 8 JDK installed.
-
Download a link:http://vertx.io/downloads.html [Vert.x 3 distribution]
-
Unzip it somewhere on your disk (e.g. in your home directory)
-
Set your
PATH
environment variable to include the installation directory -
Test the install by typing
vertx -version
.
The Vert.x core examples contains a wide range of examples using just Vert.x Core.
Apex is a toolkit for building web applications using Vert.x
The Vert.x Apex examples contains a wide range of examples using Vert.x Apex
Vertx-unit is a toolkit for writing asynchronous tests. We include some examples of how to use this tool to test your Vert.x (or other asynchronous) applications.
The Vert.x Unit examples shows how to use Vert.x Unit.