Performance Zone is brought to you in partnership with:

I've been in the world of software development for 14+ years working with most mainstream programming languages at some point. Chad is a DZone MVB and is not an employee of DZone and has posted 38 posts at DZone. You can read more from them at their website. View Full User Profile

Getting Started With Vert.x and Java on OS X

  • submit to reddit

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.

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:

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:

$ vertx run com.giantflyingsaucer.websocketsexample.WebsocketsExample -cp ~/NetBeansProjects/WebsocketsExample/target/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.


Published at DZone with permission of Chad Lung, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)


Herry Johnson replied on Tue, 2012/06/12 - 1:03pm

You're repeating yourself, you won't get anywhere by doing that. If you don't understand my answer then you should be researching it. In stead of remaining in the dark and hoping that an IDE can do all the work for you, I suggest you do what we all had to do: weeks of research and experimentation. Get to the point where you actually understand what you're trying to do.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.