| career | drupal | java | mac | mysql | perl | scala | uml | unix  

Ant example source code file (get-m2.xml)

This example Ant source code file (get-m2.xml) is included in the "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Ant tags/keywords

ant, ant_opts, ant_opts, apache, asf, for, for, license, license, m2, see, the, you, you

The get-m2.xml source code

<?xml version="1.0"?>

   Licensed to the Apache Software Foundation (ASF) under one or more
   contributor license agreements.  See the NOTICE file distributed with
   this work for additional information regarding copyright ownership.
   The ASF licenses this file to You under the Apache License, Version 2.0
   (the "License"); you may not use this file except in compliance with
   the License.  You may obtain a copy of the License at

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   See the License for the specific language governing permissions and
   limitations under the License.
   Build file to fetch maven2 tasks; extracted from (Ant's) fetch.xml
<project name="get-m2" default="get-m2" basedir=".">

  This build file downloads the Maven2 Ant tasks,
  and installs them in the location specified by the m2.dest.dir property.

  You may need to set proxy settings. On Java1.5, Ant tries to get
  this from the OS, unless you use the -noproxy option.

  Proxies can be configured manually setting the JVM proxy values in the
  ANT_OPTS environment variable.

  For example, to set the proxy up in the tcsh shell, the command would be
  something like:

  For csh/tcsh:
    setenv ANT_OPTS "-Dhttp.proxyHost=proxy -Dhttp.proxyPort=8080"
  For bash:
    export ANT_OPTS="-Dhttp.proxyHost=proxy -Dhttp.proxyPort=8080"
  For Windows, set the environment variable in the appropriate dialog box
  and open a new console. or, by hand
    set ANT_OPTS = -Dhttp.proxyHost=proxy -Dhttp.proxyPort=8080

  <property file="" />

  <property name="m2.antlib.resource"
            value="org/apache/maven/artifact/ant/antlib.xml" />

  <property name="m2.antlib.uri"
            value="antlib:org.apache.maven.artifact.ant" />

  <macrodef name="require">
    <attribute name="property" />
      <fail unless="@{property}">$${@{property}} not specified

  <target name="probe-m2">
    <require property="m2.dest.dir" />
    <require property="" />

    <!-- Look for M2 ant tasks in our classpath-->
    <property name="m2.artifact" location="${m2.dest.dir}/${}" />
    <available property="m2.antlib.found" resource="${m2.antlib.resource}" />
    <condition property="m2.antlib.typefound">
      <typefound name="${m2.antlib.uri}:artifact" />
    <available property="m2.artifact.found" file="${m2.artifact}" type="file" />

  <target name="download-m2" depends="probe-m2" unless="m2.artifact.found">
    <require property="m2.antlib.url" />
    <echo>Downloading to ${m2.dest.dir}

    <mkdir dir="${m2.dest.dir}" />
    <!-- fetch M2 ant tasks into our repository, if it is not there-->
    <get src="${m2.antlib.url}"
      usetimestamp="false" />

  <target name="dont-validate-m2-checksum" depends="probe-m2"
    <property name="checksum.equal" value="true" />

  <target name="validate-m2-checksum"
          if="m2.sha1.checksum" unless="m2.artifact.found">
    <checksum file="${m2.artifact}"
        verifyProperty="checksum.equal" />

  <target name="checksum-mismatch" depends="validate-m2-checksum"
          if="m2.sha1.checksum" unless="checksum.equal">
    <delete file="${m2.artifact}" />
      Failed to verify the downloaded file ${m2.antlib.url}" against the checksum
      coded into
      The local copy has been deleted, for security reasons

  <target name="checksum-match" depends="checksum-mismatch"
    <taskdef classpath="${m2.artifact}" resource="${m2.antlib.resource}"
             uri="${m2.antlib.uri}" />

  <target name="get-m2" depends="checksum-match"
      description="Download the Maven2 Ant tasks" />


Other Ant examples (source code examples)

Here is a short list of links related to this Ant get-m2.xml source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller


new blog posts


Copyright 1998-2021 Alvin Alexander,
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.