Automatic redeployment in Eclipse IDE

Vert.x 3.1 has (re-)in­tro­duced the re­de­ploy fea­ture. This blog post ex­plains how to use this fea­ture in the Eclipse IDE. How­ever, you can eas­ily adapt the con­tent to your IDE.

How does redeploy work

How is im­ple­mented the redeploy is not as you may ex­pect. First, the re­de­ploy does not rely on a build tool, but is in­te­grated in vert.x. How­ever you can plug your build tools with the re­de­ploy fea­ture. This fea­ture is of­fered by the io.vertx.core.Launcher class. The re­de­ploy­ment process is ac­tu­ally very sim­ple:

  1. the ap­pli­ca­tion is launched in re­de­ploy mode.
  2. it lis­tens for file changes
  3. when a match­ing file is changed, it stops the ap­pli­ca­tion
  4. it ex­e­cutes the on-redeploy ac­tions if any
  5. it restarts the ap­pli­ca­tion
  6. back to (2)

Ini­tially the ap­pli­ca­tion is launched in re­de­ploy mode. The ap­pli­ca­tion is ac­tu­ally launched in back­ground, in a sep­a­rated process. Vert.x lis­tens for file changes. You give it a set of (Ant-​style) pat­terns and every time a match­ing file changes, Vert.x stops the whole ap­pli­ca­tion and restarts it. Op­tion­ally you can con­fig­ure a on-redeploy ac­tion to plug in your build tools.

To in­te­grate this process in Eclipse (or in your IDE), you just need to con­fig­ure the set of lis­tened files, and let the Launcher class starts and stops your ap­pli­ca­tion.

Redeploy in Eclipse

The fol­low­ing screen­cast ex­plains how you con­fig­ure a vert.x ap­pli­ca­tion to be run in Eclipse and how to con­fig­ure the re­de­ploy:

To sum­ma­rize the last con­fig­u­ra­tion:

  • it’s a Java ap­pli­ca­tion con­fig­u­ra­tion
  • it uses io.vertx.core.Launcher as main class
  • In the Pro­gram ar­gu­ments (Ar­gu­ments tab), write: run org.acme.verticle.MyMainVerticle --redeploy="src/**/*.java" --launcher-class=io.vertx.core.Launcher

Redeploy with your own Main class

Let’s now imag­ine that you have your own Main class, start­ing your ap­pli­ca­tion. For in­stance, it can be some­thing like:

package org.acme.vertx;

import io.vertx.core.Vertx;

public class Main {

    public static void main(String[] args) {
        Vertx vertx = Vertx.vertx();
        vertx.deployVerticle(MyMainVerticle.class.getName());
    }

}

The re­de­ploy fea­ture from vert.x lets you use your own Main class:

  1. Cre­ate an­other Run con­fig­u­ra­tion
  2. Set the Main-Class to io.vertx.core.Launcher (yes, the one from vert.x not yours)
  3. In the ap­pli­ca­tion pa­ra­me­ter add: run --redeploy="src/**/*.java" --launcher-class=org.acme.vertx.Main

With this con­fig­u­ra­tion, the ap­pli­ca­tion is launched in back­ground using your own Main class, and will restart the ap­pli­ca­tion every time you change your source code (you can even change the source code of your Main class).

Next post

ECMAScript 6/7 on the JVM with TypeScript and Vert.x

I figured it would be a good idea to give you a couple of examples how teaming Vert.x and TypeScript helps you use ECMAScript 6 and 7 features on the JVM today.

Read more
Previous post

Vert.x 3.2.0 is released!

We are pleased to announce the release of Vert.x 3.2.0!

Read more
Related posts

Unit and Integration Tests

Let’s refresh our mind about what we developed so far in the introduction to vert.x series. We forgot an important task. We didn’t test the API.

Read more

Some Rest with Vert.x

This post is part of the Introduction to Vert.x series. Let’s go a bit further this time and develop a CRUD-ish application

Read more

Vert.x featuring Continuous Delivery with Jenkins and Ansible

This blog entry describes an approach to adopt Continuous Delivery for Vert.x applications using Jenkins and Ansible by taking advantage of the Jenkins Job DSL and Ansible plugins.

Read more