Wednesday, 7 December, 2016 UTC


Summary

The all new fabric8 Vert.x Maven Plugin allows you to setup, package, run, start, stop and redeploy easily with a very little configuration resulting in a less verbose pom.xml.
The plugin is developed under the fabric8 umbrella
Traditionally Vert.x applications using Apache Maven need to have one or more of the following plugins:
  • Maven Shade Plugin - aids in packaging a uber jar of Vert.x application with additional configurations to perform SPI combining, MANIFEST.MF entries etc.,
  • Maven Exec Plugin - aids in starting the Vert.x application
  • Maven Ant Plugin - aids in stopping the running Vert.x application
Though these are great plugins and do what is required, but at the end of the day the developer is left with a verbose pom.xml which might become harder to maintain as the application or its configuration grows. Even if we decide to go this way and use those plugins, there are some things which can’t done or done easily:
  • run an application on foreground - which is a typical way during development where the application starts in foreground of Apache Maven build and killed automatically once we hit Ctrl + c(or CMD + c on Mac)
  • redeploy is one of the coolest feature of Vert.x allowing us to perform hot deployments. Still we can manage to do this with IDE support but not natively using Apache Maven - typical cases where we disable Automatic Builds via IDE
  • setup Vert.x applications with sensible defaults and required Vert.x dependencies e.g. vertx-core
In this first blog of fabric8 Vert.x Maven Plugin series we will help you to get started with this new fabric8 Vert.x Maven Plugin, highlighting how this plugin helps alleviating the aforementioned pain points with a less verbose pom.xml.
The Apache Maven plugin source code is available at github with Apache Maven plugin documentation available at fabric8 Vert.x Maven Plugin
The source code of the examples used in this blog are available at github
Let’s set it up
Its very easy to setup and get started. Let’s say you have a project called vmp-blog with the following content as part of your pom.xml
To package the Vert.x application, run the following Apache Maven command from the project directory:
mvn clean package
On successful run of the above command you should see the file with name ${project.finalName}.jar created in the ${project.build.directory}, you could now do the following to start and run the Vert.x application.
java -jar ${project.build.directory}/${project.finalName}.jar
The generated MANIFEST.MF file is as shown below:
Main-Class io.vertx.core.Launcher Main-Verticle io.fabric8.blog.MainVerticle Manifest-Version 1.0
The source code up to now is available in here

SPI Combination

The package goal by default does a SPI combination, lets say you have a service file called com.fasterxml.jackson.core.JsonFactory in ${project.basedir}/src/main/resources/META-INF/services with contents:
foo.bar.baz.MyImpl ${combine}
During packaging, if the fabric8 Vert.x Maven Plugin finds another com.fasterxml.jackson.core.JsonFactory service definition file within the project dependencies with content foo.bar.baz2.MyImpl2, then it merges the content into com.fasterxml.jackson.core.JsonFactory of ${project.basedir}/src/main/resources/META-INF/services, resulting in the following content:
foo.bar.baz.MyImpl foo.bar.baz2.MyImpl2
The position of ${combine} controls the ordering of the merge, since we added ${combine} below foo.bar.baz.MyImpl all other SPI definitions will be appended below foo.bar.baz.MyImpl
What’s next ?
It’s good to have the jar packaged and run using java -jar uber-jar, but when doing typical development you don’t want to do frequent Apache Maven packaging and wish to see your changes automatically redeployed.
Don’t worry!!! As part of fabric8 Vert.x Maven Plugin we have added the incremental builder to Apache Maven build, which will watch for your source and resource changes to perform automatic re-build and delegate the redeployment to Vert.x.
Run, redeploy and other features of the fabric8 Vert.x Maven Plugin will be explored in detail in the next part of this series, until then have fun with fabric8 Vert.x Maven Plugin!!