Ant的应用学习

来源:互联网 发布:怎么看自己淘宝店网址 编辑:程序博客网 时间:2024/06/10 09:01

知识点:
一.学习ANT
1.<target ></target>和<target />等同
2.每个ANT文件里必须有一个build.xml文件,每个build.xml对应一个project,每个project对应几个target,每个target对应一个类,这种模式将有助于使工程结构细化和明朗化,对于开发进程和以后的升级维修都极有用处,以后要强迫自己用!
3.target可以设置depends属性,用于在执行这个target前必须执行depends这个target
4.Properties的实现与作用:
   a. 实现:可在当前目录下创建一个build.properties的文件(扩展名为 .properties),在此文件中添加值(如:dir.class = class).然后在当前build.xml文件中创建一<property></property>标签对,在其中设置file属性,值设置为目录下的build.properties(如不同一目录下将在前添加相对路径)。
   b. 作用:当在大量处理相同路径下的文件时,可通过改动build.properties中的值从而改变所有在 build.xml中的所有相关的项。
例如:
build.porperties中对应值为:
       dir.src = src
       dir.class = class    (其中,src代表源文件夹、class代表目标文件夹)
built.xml文件对应代码如下:
<project name = "testAnt" default = "run">
    <property file = "build.properties" />    <!--  properties在built.xml中的引用 -->
    <target name = "make">
     <mkdir dir = "class"></mkdir>
    </target>
    <target name = "complie">
           <固定格式:${},在{}中添加built.porperties中的值>
     <javac srcdir = "${dir.src}" destdir = "${dir.class}" />
    </target>
    <target name = "run" depends = "complie">
     <java classname = "Hello" classpath = "class" />
    </target>
</project>

5.build.xml的标准结构
 <project name="MyProject" default="dist" basedir=".">
    <description>
        simple example build file
    </description>
  <!-- set global properties for this build -->
  <property name="src" location="src"/>
  <property name="build" location="build"/>
  <property name="dist"  location="dist"/>

  <target name="init">
    <!-- Create the time stamp -->
    <tstamp/>
    <!-- Create the build directory structure used by compile -->
    <mkdir dir="${build}"/>
  </target>

  <target name="compile" depends="init"
        description="compile the source " >
    <!-- Compile the java code from ${src} into ${build} -->
    <javac srcdir="${src}" destdir="${build}"/>
  </target>

  <target name="dist" depends="compile"
        description="generate the distribution" >
    <!-- Create the distribution directory -->
    <mkdir dir="${dist}/lib"/>

    <!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
    <jar jarfile="${dist}/lib/MyProject-${DSTAMP}.jar" basedir="${build}"/>
  </target>

  <target name="clean"
        description="clean up" >
    <!-- Delete the ${build} and ${dist} directory trees -->
    <delete dir="${build}"/>
    <delete dir="${dist}"/>
  </target>
</project>
6.? 专家模式:谁最了解,持有数据,就让谁处理该事件,这就叫专家模式。
   例如:
   a. 电视和关电视的人?
      ——由于是电视清楚关电视的操作,了解关电视的过程,因此电视去关而不是人去关,人只是发出了一      个关电视的动作,具体怎么进行关电视的操作而是有电视去实施的。
   b. 票据和售货员?
      ——由于票据持有所有有关数据,因此在统计总额时是又票据去进行数据处理,而不是人,人只是可能     发出统计的命令。
   c. 门与关门的人?
      ——由于门自己最清楚自己的构造,怎么样才能关上门,因此是又门去处理关门这一事件,而不是人,      人只可能发出关门的命令,而具体怎么关是有门去实施

二.批处理程序
echo off用于去除命令本身,不显示;@用语不显示紧随其后的命令
三.多读英文文档


学习感受
今天是开学的第一天,大批量的练习,和优秀同学之间的差距,残酷的竞争让我心情很复杂,一直相对优秀的我,猛一下难以接受这个现实,尤其是和同学的差距。昨天1点睡的,早晨6点就醒了,沉重的压力让我睡不着,早早就起来打开电脑写程序。我个性比较强,在那方面都不甘示弱。虽然现在我和优秀的同学还有差距,我相信我的努力总有一天会得到回报。相信自己,你会证明自己的。fighting!