Tuesday, April 21, 2009

Ant gets jar file from maven dependency

Sometimes, we need ant work with maven together. Here is an example which let ant copy a jar file which is defined in dependency in pom.xml.

Dependency in pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>

  <artifactId>ant-contrib</artifactId>
  <packaging>pom</packaging>
  <name>Ant Contrib</name>
  <description>Ant Contrib Dependencies</description>
  <dependencies>
    <dependency>
      <groupId>ant-contrib</groupId>
      <artifactId>ant-contrib</artifactId>
      <version>1.0b2</version>
      <scope>compile</scope>
      <exclusions>
        <exclusion>
          <groupId>ant</groupId>
          <artifactId>ant</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
  </dependencies>
</project>

 

Here is the build xml of ant.

<project ... xmlns:artifact="antlib:org.apache.maven.artifact.ant"

    <!-- pom -->
    <artifact:pom id="ant.contrib.maven.project" file="../../ant/ant-contrib/pom.xml" />
   

    <artifact:dependencies filesetId="ant.contrib.dependency.fileset"
        pathId="ant-contrib.setup.lib.path" settingsFile="../../ant/maven-settings.xml">
        <pom refid="ant.contrib.maven.project" />
    </artifact:dependencies>

    <target name="prepare-ant-contrib">
        <mkdir dir="target" />
        <copy tofile="target/lib/ant-contrib.jar" flatten="true">
            <fileset refid="ant.contrib.dependency.fileset" />
        </copy>
    </target>
    ...

No comments:

Post a Comment