ANT Migration steps

ANT Setup
To install and configure Ant
1.Download Apache Ant version 1.6 or newer to a directory of your choice: http://ant.apache.org/bindownload.cgi. This directory will be known as ANT_HOME. Once the files are on your computer, there is no further installation required.

To see if you have Ant installed: 1. Open a command prompt. 2. At the prompt, type ant -version and press Enter.
JAVA Setup Download JAVA latest version and install Create a New User Variable and named as JAVA_HOME and set path as shows in below screenshot.
To see if you have Java installed: 1. Open a command prompt. 2. At the prompt, type java -version and press Enter.
Installing the Force.com Migration Tool
1. Log into a Salesforce organization.
2. From Setup, click Develop--> Tools and select Force.com Migration Tool
3. Save the .zip file locally and extract the contents to the directory of your choice.
4. Copy ant-salesforce.jar and paste into your Ant installation's lib directory. The lib directory is located in the  root folder of your Ant installation.
To start with deployment using ANT, we will need “build.xml” and “build.properties” file. As there is no need of “build.properties” however its good to have it so that the configuration related settings are in different file. You can copy both files from “sample” folder of unzipped content from salesforce.
  
# build.properties

# Proxy settings
proxy.host =xxx.xx.x.xx
proxy.port =xxxx
proxy.user =xxxxxx
proxy.pwd =xxxxxx

# Target Salesforce Org Credentials
sf.serverurl =https://login.salesforce.com
sf.username =xxxxx@salesforce.com
sf.password =xxxxxxxxdmfl6wFj3vrdNbcJed
  
Create “build.properties” from above code snippet or copy it from unzipped folder. Now create “build.xml” needed by ANT. Following is the example of build.xml file:
  
     
     <project name="Sample usage of Salesforce Ant tasks" default="test" basedir="." xmlns:sf="antlib:com.salesforce">

    <property file="build.properties"/>
    <property environment="env"/>

    <!-- Setting default value for username, password and session id properties to empty string 
         so unset values are treated as empty. Without this, ant expressions such as ${sf.username}
         will be treated literally.
    -->
  
 <condition property="proxy.need">
  <and>
  <isset property="proxy.host"/>
  <isreachable host="${proxy.host}"/>
  </and>
 </condition>

 <target name="proxy" if="proxy.need">
  <echo>Set Proxy Parameters</echo>
  <property name="proxy.host" value="${proxy.host}" /> 
  <property name="proxy.port" value="${proxy.port}"/>
  <property name="proxy.user" value="${proxy.user}"/>
  <property name="proxy.pwd" value="${proxy.pwd}"/>
  <setproxy proxyhost="${proxy.host}" proxyport="${proxy.port}" proxyuser="${proxy.user}" proxypassword="${proxy.pwd}" />
 </target> 
 
 
    <condition property="sf.username" value=""> <not> <isset property="sf.username"/> </not> </condition>
    <condition property="sf.password" value=""> <not> <isset property="sf.password"/> </not> </condition>
    <condition property="sf.sessionId" value=""> <not> <isset property="sf.sessionId"/> </not> </condition>

    <taskdef resource="com/salesforce/antlib.xml" uri="antlib:com.salesforce">
        <classpath>
            <pathelement location="../ant-salesforce.jar" />         
        </classpath>
    </taskdef>
 
 <!-- TO retrive metadata -->
 <target name="retrieveCode" depends="proxy" >
      <!-- Retrieve the contents listed in the file codepkg/package.xml into the codepkg directory -->
      <sf:retrieve username="${sf.username}" password="${sf.password}" serverurl="${sf.serverurl}" retrieveTarget="codepkg"  unpackaged="codepkg/package.xml"/>
 </target> 
 
 <!-- TO Validate code -->
 
 <target name="deployCodeCheckonly" depends="proxy" >
      <!-- Upload the contents of the "codepkg" directory, running the tests for just 1 class -->
      <sf:deploy username="${sf.username}" password="${sf.password}" serverurl="${sf.serverurl}" deployRoot="codepkg" checkOnly="true">
   
   <runtest>testClassname1</runtest>
   
      </sf:deploy>
    </target> 
 
 
 <!-- To Deploy -->
   <target name="deployCode" depends="proxy">
   <sf:deploy username="${sf.username}" password="${sf.password}" serverurl="${sf.serverurl}" deployRoot="codepkg">
   <runtest>testClassname1</runtest>
   <runtest>testClassname2</runtest>
   
   </sf:deploy>
    </target>  
 
</project>

  

If your system having any proxy config.Please set proxy in CMD prompt
set HTTP_PROXY=http://userName:pass@xx.xxx.xx.xxx:portNumber
set HTTPS_PROXY=http://userName:pass6@xxx.xx.xx.xxx:portNumber


Please find the below image for command prompt ref.