Category Archives: ant

Running Jetty 9 with Ant

We have a simple web application written in Spring MVC. Today, we will demo how to run the war through Ant, using Jetty 9. The needed libraries can either be manually downloaded and provided as a part of the project. However, sometimes, it becomes unwieldy, especially if you want to upgrade the Jetty version. So, we will define them as Maven dependencies in the build.xml.

The beauty of defining the required jars as Maven dependencies is, that these jars will be downloaded in local Maven repository if not present.

Note that we define the location of the war file. Also, we define a custom port and a context path.

The source code can be found here:

https://github.com/paawak/blog/tree/master/code/simple-spring-rest

Invoking Ant from Maven: The Maven AntRun Plugin

Context

In my previous entries, Accessing Maven dependencies through Ant: Part 1 and Part 2 , I had been talking about how we can explore Maven dependencies from Ant. Here, we will talk about how we can do the reverse, that is, invoke Ant from within Maven. I guess this is the more common scenario of the two. Often we have encountered a legacy project which has Ant as the build tool, and we need to integrate that with Maven, often invoking the Ant’s build file from pom.xml. We will continue using our RMI Sever as an example.

We will actually use the Idiot’s paradigm © to demonstrate how to invoke Ant through Maven.

Using the Maven AntRun Plugin

Is pretty straight forward. I have created a Profile called AetherAntTaskExample, which looks like:

You invoke this by doing:

mvn clean package -P AetherAntTaskExample

The ant file is invoked and executed. The original pom.xml can be found here.

Accessing Maven dependencies through Ant: Part 2: The Aether Ant Tasks

Context

This is the 2nd increment of this series. Here is Part 1:

http://palashray.com/accessing-maven-dependencies-through-ant-part-1-the-maven-ant-tasks/

The context and the problem remains same: we want to access Maven dependencies through Ant. We will continue using the Rmi Server as an example.

What is Aether?

Aether is an API which facilitates accessing artifacts from various repositories like Maven, Nexus, Central, etc. From Maven 3 onwards, Maven is fully Aether compliant.

Disclaimer

I was not able to get Aether work on a complex Maven project having both Spring 2.x and 3.x: it invariably messes up. But with simpler modules, it seems to work fine. Though Aether is still very much bleeding edge and yet to stabilize, I believe thats the way to go, as it makes accessing artifacts language agnostic.

Using the Aether Ant Tasks

This is how my ant file build-with-aether-ant-task.xml looks like:

Invoking Ant

Use the following command:

ant -f build-with-aether-ant-task.xml -Dproject.name=rmi-server -Dproject.version=1.0

You should see a zip with all the dependencies in the target folder.

Accessing Maven dependencies through Ant: Part 1: The Maven Ant Tasks

Context

I have a project which is managed by Maven. Suppose for some reason, best know to me :), I want to do the following using Ant:

  1. Inspect the project’s dependencies
  2. Zip all the dependencies together

This can be achieved by using the Maven Ant Tasks.

Project Structure

We will take the Rmi Server as an example to demonstrate how we can access Maven dependencies in Ant through the Maven Ant Tasks.

The pom.xml looks like this:

Building the project with Ant

The following is how my ant file, build-with-maven-ant-task.xml, looks:

Invoking Ant

From the command prompt, issue the following command:

ant -f build-with-maven-ant-task.xml -Dproject.name=rmi-server -Dproject.version=1.0

In the target folder, you should see the rmi-server-1.0.zip, containing all the dependencies of the project.