• 【转】Ant学习笔记——自己构建Ant编译环境


    自从年初开始用NetBeans6.0,才接触到Ant。 这是今年6月份的一篇Ant学习笔记。
    安装 1.下载并构建环境。   去官网下载src包和bin包。解压缩它们到同一目录,运行build.bat,bootstrap.bat。 2.设置系统环境变量   新建ANT_HOME,值为解压缩的目录。如C:antapache-ant-1.7.0   在PATH末尾追加%ANT_HOME%in; 3.测试安装环境   命令行下输入ant -version,成功看到Ant版本信息。
    运行 1.建一个项目文件夹firsttest 2.把项目开发完成的文件和文件夹放到firsttest下   例:java文件的文件夹src,web文件的文件夹web 3.firsttest下新建文件build.xml,编辑如下: 

    <?xml version="1.0" encoding="UTF-8"?>                                                                           <project name="ant_firsttest" default="dist" basedir=".">                                       <description>ant firsttest!</description>                                                                                <!-- set global properties for this build -->           <!--设定变量,之后用。location为文件夹路径-->                               <property name="src" location="src"/>                                       <property name="build" location="build"/>                                       <property name="dist"  location="dist"/>                                       <property name="web"  location="web"/>                                                   <!--设置properties文件位置.这里没用到。-->                                          <!--<property file="nbproject/project.properties"/>-->                                    
      <!--初始化命令-->                                       <target name="init">                                         <!-- Create the time stamp -->                                         <tstamp/>                                                          <!--mkdir是建立文件夹,${build}即刚才设定的变量。这几行都在干这事。-->         <!-- Create the build directory structure used by compile -->                                         <mkdir dir="${build}/WEB-INF/lib"/>                                         <mkdir dir="${build}/WEB-INF/classes"/>                                                                                    <mkdir dir="${build}/WEB-INF/classes/javafile/package1"/>                                               <mkdir dir="${build}/WEB-INF/classes/javafile/package2"/>                                                                                            </target>                                    
      <!--编译-->                                       <target name="compile" depends="init"                                             description="compile the source " >                                                                                      <!-- Compile the java code from ${src} into ${build} -->                                         <!--javac标签用来设置编译程序的参数,srcdir为java文件路径,destdir为编译后class文件的保存路径。-->     <javac srcdir="${src}/javafile/package1" destdir="${build}/WEB-INF/classes/javafile/package1"/>                                         <javac srcdir="${src}/javafile/package2" destdir="${build}/WEB-INF/classes/javafile/package2"/>                                         <!--如果路径下还有别的文件需要一起打包,用copy 命令。-->         <copy file="${src}/hello_ant.xml" tofile="${build}/WEB-INF/classes/hello_ant.xml" />                                                                                                                         </target>                                                    <!--编译后就要打包了。-->                                       <target name="dist" depends="compile"                                             description="generate the distribution" >                                         <!-- Create the distribution directory -->                                         <mkdir dir="${dist}"/>                                                                   <!--像jsp,jar这些直接用不用编译的文件,直接用copy命令。-->                                     <copy file="${web}/image/a.gif" tofile="${build}/image/a.gif" />                                         <copy file="${web}/WEB-INF/web.xml" tofile="${build}/WEB-INF/web.xml" />                                          <copy file="${web}/WEB-INF/lib/a.jar" tofile="${build}/WEB-INF/lib/a.jar" />                                               <copy file="${web}/index.jsp" tofile="${build}/index.jsp" />                                                       <!--最后用jar命令打成jar/war文件,文件名和后缀随便起。basedir为欲打包的原文件路经-->                                         <jar jarfile="${dist}/ant_firsttest.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>                                       

    4.控制台在firsttest目录,输入ant后回车就打包完成了!   注:输入ant回车自动执行init,compile,dist命令。要想执行clean命令,输入ant clean即可。

    转载地址:http://www.blogjava.net/atealxt/archive/2008/07/17/ant_study_note.html

  • 相关阅读:
    hdu 2132 An easy problem
    ACM暑假培训宣讲稿
    hdu Lovekey(水题)
    windows 下c++编译
    semantic
    could not open XXX permission denied
    sv_target_output dx11
    hlsl 的tex函数
    effect state dx11
    cg 到hlsl的转换
  • 原文地址:https://www.cnblogs.com/201dom/p/4971676.html
Copyright © 2020-2023  润新知