ant 日记

1、ant安装

     

      1 添加ANT-HOME 环境变量,即ant所在目录


      2 ANT-HOME下的bin目录加入到path环境变量中

      3 cmd下输入ant看是否成功

2  ant默认是处理当前目录下的build.xml,即在cmd下只输入ant命令,若想处理别的xml文件则可以用 ant –f xxx.xml

 

build.xml 

<?xml version="1.0" encoding="utf-8"?>
<project default="init">
				<target name="init">
					<mkdir dir="helloword/a/b"/>
				</target>
</project>

 

3、模式匹配

  1、src*/*.java  匹配带src前缀的任何目录中的所有java文件

  2、** 匹配任意数量(层)的目录,例如**/*.java  匹配当前目录下的所有java文件

 

4、打jar

<?xml version="1.0"?>
<project name="javaTest" default="jar" basedir=".">
    <target name="clean">
       <delete dir="build"/>
    </target>
    <path id="classpath">  
        <fileset  dir="lib">
          <include name="*.jar"/>
        </fileset>
    </path>
    <target name="compile" depends="clean">
       <mkdir dir="build/classes"/>
      <javac srcdir="src" destdir="build/classes" encoding="UTF-8">
          <classpath refid="classpath"/>   
      </javac>
    </target>
    <target name="run" depends="compile">
       <java classname="Main">
           <classpath>
              <!--<classpath refid="classpath"/>-->
              <pathelement path="build/classes"/>
           </classpath>
       </java>
    </target>
    <target name="copyConfig" depends="run">   
        <copy todir="build/classes">   
                <fileset dir="src">
                     <include name="*.png" />
                </fileset>
        </copy>          
    </target>    

    <target name="jar" depends="copyConfig">  
	<!-- create a property containing all .jar files, prefix lib/, and seperated with a space -->          
	<pathconvert property="mf.classpath" pathsep=" ">
             <mapper>
                 <chainedmapper>
			<!-- remove absolute path -->    
                     <flattenmapper />
			<!-- add lib/ prefix -->    
                     <globmapper from="*" to="lib/*" />
                 </chainedmapper>
             </mapper>
             <path refid="classpath" />
         </pathconvert>


    <jar destfile="main.jar" basedir="build/classes">
               <manifest>
                  <attribute name="Main-class" value="Main"/>
                      <attribute name="Class-Path" value="${mf.classpath} "/>
               </manifest>
     </jar>
    </target>
</project>


你可能感兴趣的:(java,ant)