当前位置:网站首页>Ant Usage Summary (II): description of related commands

Ant Usage Summary (II): description of related commands

2022-06-23 06:00:00 linchaolong

stay ant Installation directory manual Directory is ant Description document , open index.xml, Click on Using Apache ant There are instructions .


Related command description


Specify profile


perform ant command , The default is... In the current directory build.xml, Can pass -f Specify profile .
Example :ant -f Profile path

project


attribute :
name: Project name
default: Default execution target

target


<target> It's a container , Command set , A business .
attribute :
depends: Dependencies , Execute this target What needs to be executed before target.
name: name

Example :
<target name="A" > 
<target name="B" depends="A"> 
<target name="C" depends="A,B">

Execute the specified... On the command line target:ant targetName

property


ant Properties in , It's equivalent to defining a variable , adopt ${ Property name } quote .
attribute :
name: Variable name
value: value
file: Property configuration file path , In the configuration file, the key=value Format configuration properties of . Example : <property file="local.properties" />
environment: Give environment variables an alias ​

Example :
<property name="a" value="aaa" />
<target name="print">
  <echo>${a}</echo>
</target>

import


Contains a file ,project Of name Property values cannot conflict .optional Indicates whether the file is optional .
<import file="test2.xml" optional="true" />

condition


condition A tag can define the value of a variable through conditional judgment .
	<property name="a" value="aaa" />
	
	<!--
	<property name="b" value="bbb" />
	-->
	
	<!--  If the property is set b Then the value is ${b}, Otherwise, it's worth ${a}-->
    <condition property="val" value="${b}" else="${a}">
        <!--  Determine whether the specified attribute is set  -->
        <isset property="b" />        
    </condition>

propertyfile


Save the properties to a file
attribute :
file: File path
    <propertyfile file="auto.prop">
    	<!--  preservation auto.umeng.channel=${a} To the file  -->
        <entry key="auto.umeng.channel" value="${a}" />
    </propertyfile>

copy


1. Copy a single file to the specified path
<copy file="a.txt" tofile="b.txt" />

2. Copy a single file to a specified directory
<copy file="a.txt  " todir="../tmpdir  " /  >

3. Copy one directory to another
<copy todir="../destDir">
  <fileset dir="srcDir" />
</copy>

4. Copy a batch of files to the specified directory
<copy todir="../destDir">
  <fileset dir="srcDir">
    <include name="**/*.java">
    <exclude name="**/Test.java"> 
  </fileset>
</copy>

<copy todir="../destDir">
  <fileset dir="srcDir" excludes="**/*.java"/>
</copy>


delete


1. Delete a file
<delete file="a.txt" />

2. Delete the specified directory and its subdirectories
<delete dir="dir" />

3. Delete a specified set of files
<delete>
  <fileset dir="." includes="**/*.bak" />
</delete>


move


1. Move or rename a file
<move file="a.txt" tofile="b.txt" />

2. Move a file to the specified directory
<move file="a.txt" todir="destDir" />

3. Move one directory to another
<move todir="destDir">
  <fileset dir="srcDir" />
<move/>

4. Move a group of files to another directory
<move todir="destDir">
  <fileset dir"srcDir">
     <include name="**/*.jar" />
     <exclude name="**/ant.jar" /> 
  </fileset>
</move>

javac


<javac srcdir=" Source directory " destdir=" Compile output directory " classpath=" Rely on the jar File or class directory " debug="on Indicates input log information ,off No output " includes=" Include files " excludes=" Ignore files " />

java


<java classname=" The full pathname of the class being executed ">
<classpath>
<pathelement location="xxx.jar" />
<pathelement path="classpath" />
</classpath>
</java>

pathelement Can pass location Property contains a jar Or by path Property contains a classpath .classpath Used to set the environment variables to be used .

jar


<jar destfile="xxx.jar" basedir="./classes" includes="./lib/**( contain lib All files in the directory )" excludes="**/Test.class( Ignore all Test.class)" manifest=" Customize mf File naming "/>

if


if Decide whether to carry out some operations through conditional judgment .
	<!--  If the condition holds , Call print -->		
	<if>
		<!--  Judge whether the specified attribute value is true -->
        <!--
        <istrue value="${a}" />
        -->
        
		<!--  Determine whether the specified attribute is set  -->
		<!--
		<isset property="prop"/>
		-->
		
		<!--  Determine if two values are equal  -->
    	<equals arg1="${channel}" arg2="2" />
    <then>
        <antcall target="print" />
    </then>
	</if>
antcall The tag is used to call a target.

script


script Tags are used to insert script code .
Example : Get the current time and set it to the property time Value .
<script language="javascript">
            <![CDATA[
                project.setProperty("time",Math.floor((new Date()).getTime()/1000));
            ]]>
    </script>

Time stamp


Format the current time and set the properties time.
    <tstamp>
      <format property="time"
                  pattern="yy.M.d.HHmm" />
    </tstamp>

Add custom jar To ant Of classpath


	<!--  add to ant-contrib-1.0b3.jar To classpath -->
	<taskdef resource="net/sf/antcontrib/antcontrib.properties">
        <classpath>
            <pathelement location="${env.ANT_ROOT}\lib\ant-contrib-1.0b3.jar" />
        </classpath>
    </taskdef>

ant Implementing iterations in


because ant Iteration itself is not supported , So we need to use a third-party library ant-contrib To implement the iteration function .
download ant-contrib, And will ant-contrib-1.0b3.jar Copy the document to ANT The installation directory .
Download address :

I'm here ant-contrib-1.0b3.jar Put it in ant Installation directory lib Under the table of contents .
Sample code :

    
	
     
	
     
	
	
     
	
     
        
      
            
       
        
      
    
     

    
     
	
     
	
	
     
		
      
		
      
   	
     
   	
	
     
  		
      
       channel = ${channel}
      
	
     

    
Running effect :


Replace the specified string


Escape character list :
&lt;< Less than no.
&gt;> More than no.
&amp;& and
&apos;' Single quotation marks
&quot;" Double quotes

    
    
    
    
    
    
    
    
    
replaceregexp The tag supports regular expressions .

Related articles :
原网站

版权声明
本文为[linchaolong]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206230421395155.html