DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
11 Monitoring and Observability Tools for 2023
Learn more
  1. DZone
  2. Coding
  3. Java
  4. Setting up a Vert.x Project to Work with Maven and NetBeans IDE 7.1 on OS X and Java 7

Setting up a Vert.x Project to Work with Maven and NetBeans IDE 7.1 on OS X and Java 7

Chad Lung user avatar by
Chad Lung
·
Jun. 01, 12 · Interview
Like (0)
Save
Tweet
Share
14.84K Views

Join the DZone community and get the full member experience.

Join For Free

Today I’ll show you one way to use NetBeans IDE 7.1 and Maven to work with a Vert.x project. This is just one way you can go about setting up the project and is how I currently do it. If you haven’t already done so please make sure to check out my previous article on setting up Java 7 on OS X (Lion).

Make sure NetBeans IDE is fully up to date with at least version 7.1.2 or later. Verify that Java 7 is installed as Vert.x only works with Java 7.

Start NetBeans IDE and create a new project: File -> New Project -> Maven -> Java Application

Creating a new Maven project in Netbeans

For the project name give it RouteMatchExample as I’m going to borrow some of the example code for Vert.x.

We need to ensure this project uses Java 7 so when the project is generated right-click on it and choose Properties and then select Compile and set the Java Platform to JDK 1.7.

Setting Netbeans to use the JDK 1.7 for this project

You should see a file called app.java, refactor that file’s name by right-clicking on it and choosing: Refactor -> Rename. Set the name as RouteMatchExample. Go into the file now and add this example code:

package com.giantflyingsaucer.vertxroutes;
 
import org.vertx.java.core.Handler;
import org.vertx.java.core.http.HttpServerRequest;
import org.vertx.java.core.http.RouteMatcher;
import org.vertx.java.deploy.Verticle;
 
public class RouteMatchExample extends Verticle {
 
  public void start() {
 
    RouteMatcher rm = new RouteMatcher();
 
    rm.get("/details/:user/:id", new Handler<HttpServerRequest>() {
      public void handle(HttpServerRequest req) {
        req.response.end("User: " + req.params().get("user") + " ID: " + req.params().get("id"));
      }
    });
 
    vertx.createHttpServer().requestHandler(rm).listen(8080);
  }
}

Now, we need to add the Vert.x dependencies. Since Vert.x is not on Maven Central yet you need to do this manually for now. Right-click on the Dependencies in your project and choose: Add Dependency

Adding the Vert.x dependencies

We will manually fill in the required information for Vert.x. In the dialog that opens fill in the following data:

Group Id: org.vertx
Artifact Id: vertx-core
Version: 1.0.0

Press the Add button and then add another dependency:

Group Id: org.vertx
Artifact Id: vertx-platform
Version: 1.0.0

This will add two dependencies to your project. You need to right-click on those and choose Manually Install Artifact and then navigate to wherever you placed the Vert.x installation (the Vert.x jars are in the lib/jars folder).

Your Maven POM file will have the following dependencies now:

<dependencies>
    <dependency>
        <groupId>org.vertx</groupId>
        <artifactId>vertx-core</artifactId>
        <version>1.0.0</version>
    </dependency>
    <dependency>
        <groupId>org.vertx</groupId>
        <artifactId>vertx-platform</artifactId>
        <version>1.0.0</version>
    </dependency>
</dependencies>

In the POM file let’s add some code to make life a little easier which will move over any additional jar files we might add to our project in the future. This will copy those dependent jars from your project into the Vert.x mod location where you can create a new mod. The Maven xml for this looks like the following (tweak as needed for your settings):

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <version>2.4</version>
    <executions>
        <execution>
            <id>copy-dependencies</id>
            <phase>package</phase>
            <goals>
                <goal>copy-dependencies</goal>
            </goals>
            <configuration>
                <outputDirectory>/Users/chadlung/vert.x-1.0.final/mods/RouteMatchExample/lib</outputDirectory>
                <overWriteReleases>false</overWriteReleases>
                <overWriteSnapshots>false</overWriteSnapshots>
                <overWriteIfNewer>true</overWriteIfNewer>
            </configuration>
        </execution>
    </executions>
</plugin>

The important this here is I’m moving my dependent jars to the following folder: /Users/chadlung/vert.x-1.0.final/mods/RouteMatchExample/lib Of course you need to create the folder RouteMatchExample/lib in the Vert.x mod folder. Read up on modules if you don’t understand them before proceeding.

The other thing you need to do is to copy the class files you generate over to the mod project folder. Since the package I used is: com.giantflyingsaucer.vertxroutes you need to create a folder structure in your project’s mod folder like this: /Users/chadlung/vert.x-1.0.final/mods/RouteMatchExample/com/giantflyingsaucer/vertxroutes

The mod project structure

In order to get the class file(s) copied over I used Maven again utilizing the maven-resources-plugin. The POM xml looks like this for that part:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-resources-plugin</artifactId>
    <version>2.5</version>
    <executions>
        <execution>
            <id>copy-resources</id>
            <phase>package</phase>
            <goals>
                <goal>copy-resources</goal>
            </goals>
            <configuration>
                <overwrite>true</overwrite>
                <outputDirectory>/Users/chadlung/vert.x-1.0.final/mods/RouteMatchExample/com/giantflyingsaucer/vertxroutes/</outputDirectory>
                <resources>
                    <resource>
                        <directory>${project.build.directory}/classes/com/giantflyingsaucer/vertxroutes/</directory>
                    </resource>
                </resources>
            </configuration>
        </execution>
    </executions>
</plugin>

Now every time you build the project any dependencies are moved over and any class files are as well. Keep in mind though the Vert.x jars are moved into the mod folder as well, those are not actually needed as they are already on the classpath. From the Terminal you can easily run a Vert.x mod by doing the following (make sure Vert.x is on your path):

$ vertx run RouteMatchExample

From a web browser you should be able to use the following URL to generate a result: http://localhost:8080/details/Chad/123

Result:

User: Chad ID: 123

My entire POM looks like this:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
 
    <groupId>com.giantflyingsaucer</groupId>
    <artifactId>VertxRoutes</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
 
    <name>VertxRoutes</name>
    <url>http://maven.apache.org</url>
 
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
 
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.vertx</groupId>
            <artifactId>vertx-core</artifactId>
            <version>1.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.vertx</groupId>
            <artifactId>vertx-platform</artifactId>
            <version>1.0.0</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.4</version>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>/Users/chadlung/vert.x-1.0.final/mods/RouteMatchExample/lib</outputDirectory>
                            <overWriteReleases>false</overWriteReleases>
                            <overWriteSnapshots>false</overWriteSnapshots>
                            <overWriteIfNewer>true</overWriteIfNewer>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.5</version>
                <executions>
                    <execution>
                        <id>copy-resources</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <overwrite>true</overwrite>
                            <outputDirectory>/Users/chadlung/vert.x-1.0.final/mods/RouteMatchExample/com/giantflyingsaucer/vertxroutes/</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>${project.build.directory}/classes/com/giantflyingsaucer/vertxroutes/</directory>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

Thats one way to setup a Vert.x mod project in NetBeans IDE 7.1 using Maven. Leave a comment if you have a better way of doing any of this as I’m always trying to make things easier, thanks.

Integrated development environment Vert.x Java (programming language) Apache Maven NetBeans MOD (file format)

Published at DZone with permission of Chad Lung, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Unlocking the Power of Elasticsearch: A Comprehensive Guide to Complex Search Use Cases
  • Spring Boot vs Eclipse Micro Profile: Resident Set Size (RSS) and Time to First Request (TFR) Comparative
  • Create a REST API in C# Using ChatGPT
  • 10 Best Ways to Level Up as a Developer

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: