Getting started with Vert.x and Java on OS X

Post to Twitter

Vert.x is a fairly new project that has already reached 1.0 status and has a growing community. According to their website Vert.x is: Effortless asynchronous application development for the modern web and enterprise. If your familiar with Node.js then you will most likely feel right at home with Vert.x. Vert.x also allows you to use a favorite language like Java, Ruby, Groovy, or JavaScript with support for Scala and Python coming in the future. Today I’ll go over a very simple demo on how to try out Vert.x using Java.

[ad name=”Google Adsense”]

Vert.x currently uses Apache Ant and I was curious to start using Vert.x but without having to setup Ant, etc. What follows are the steps I took to get the WebSockets example working on my OS X machine without using Ant.

First off, you need Java JDK 1.7 installed and that means if your on OS X then you need to be running Lion 10.7.2+. See my previous post on how to install the JDK 1.7 on OS X.

At some point it looks like the Vert.x artifacts will be on Maven Central, but until then you can download the binaries here. Once you’ve extracted the files to a convenient location on your hard drive set your path to point to the Vert.x bin folder. My .bash_profile file looks like this in my case (if you don’t have .bash_profile check for a file called .profile):

export PATH=/Users/chad3925/$PATH

From the Terminal you should be able to then run the following command:

$ vertx version

Using some of the example code I modified it slightly:

package com.giantflyingsaucer.websocketsexample;


public class WebsocketsExample extends Verticle {

  public void start() {
    vertx.createHttpServer().websocketHandler(new Handler<ServerWebSocket>() {
      public void handle(final ServerWebSocket ws) {
        if (ws.path.equals("/myapp")) {
          ws.dataHandler(new Handler<Buffer>() {
            public void handle(Buffer data) {
              ws.writeTextFrame(data.toString()); // Echo it back
        } else {
    }).requestHandler(new Handler<HttpServerRequest>() {
      public void handle(HttpServerRequest req) {
        if (req.path.equals("/")) req.response.sendFile("ws.html"); // Serve the html

Grab a copy of the ws.html file from the GitHub repo and save it to where you plan to keep your resulting compiled binaries.

I used Netbeans 7.1 to create a new Maven application called WebsocketsExample and then manually brought in the dependancies (since they are not yet on Central when this article was written). My pom.xml looks like this:

<project xmlns="" xmlns:xsi=""





Note: Not all the dependancies in the above file are required for this example, I added some for additional future experimentation.

Do a clean build on the project and then drop back into the Terminal. Depending on your setup the following will differ but this is how I ran the example (from the Maven created target folder):

$ vertx run com.giantflyingsaucer.websocketsexample.WebsocketsExample -cp classes

Go to the following address in a web browser that supports websockets: http://localhost:8080

At this point if all went well you should have a server running that will talk to the web browser with websockets. You can find plenty more examples including ones for Javascript, Ruby, etc. here:

Make sure to check out the Vert.x Google Group as well as their blog. They have some initial benchmarks posted there and are quite impressive so far.

Post to Twitter

This entry was posted in Java, Online Games, Vertx. Bookmark the permalink.

3 Responses to Getting started with Vert.x and Java on OS X

  1. Pingback: Questa settimana in Grails (2012-20) - - Il blog di Luca Canducci: notizie, tips e nuove tecnologie dal mondo dell’IT.

  2. Pingback: An Army of Solipsists » Blog Archive » This Week in Grails (2012-20)

  3. Nice intro! Thanks for sharing.

    I’ve recently created a smilar entry for Maven/Eclipse – Includes eclipse launcher and an internal repo (until deps are available in a public maven repo).

Comments are closed.