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

Posted by {"name"=>"Palash Ray", "email"=>"paawak@gmail.com", "url"=>"https://www.linkedin.com/in/palash-ray/"} on August 12, 2014 · 2 mins read

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:

	
		
			
				org.springframework
				spring-framework-bom
				4.0.2.RELEASE
				pom
				import
			
		
	
	
		
			com.swayam.demo.rmi.api
			rmi-service-api
			1.0
		
		
			log4j
			log4j
			1.2.14
		
		
			org.slf4j
			slf4j-api
			1.5.8
		
		
			org.slf4j
			jcl-over-slf4j
			1.5.8
		
		
			org.slf4j
			slf4j-log4j12
			1.5.8
		
		
			org.springframework
			spring-core
			
				
					commons-logging
					commons-logging
				
			
		
		
			org.springframework
			spring-context
		
		
			net.jini
			jsk-platform
			2.2.2
		
		
			net.jini
			jsk-lib
			2.2.2
		
		
			org.apache.river
			reggie
			2.2.2
		
	

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.