<?xml version="1.0"?>

<project name="ssh" basedir="." default="usage">
      <property name="name" value="ssh"/>

<property name="war.dir" value="war"/>
      <property name="src.dir" value="src"/>
      <property name="client.dir" value="client"/>
      <property name="build.dir" value=".classes"/>
      <property name="webcontent.dir" value="WebContent"/>
      <property name="prjlib.dir" value="lib"/>    
      <property name="webcontentlib.dir" value="${webcontent.dir}/WEB-INF/lib"/>
      <property name="weblib.dir" value="${war.dir}/WEB-INF/lib"/>
      <property name="dist.dir" value="dist"/>

<property environment="env"/>
      <property name="tomcat.home" value="${env.CATALINA_HOME}"/>
      <property name="webapp.dist" value="${dist.dir}/webapps"/>   
      <path id="master-classpath">
          <fileset dir="${webcontentlib.dir}">
              <include name="hibernate3.jar"/>
              <include name="spring.jar"/>            
              <include name="struts.jar"/>            
              <include name="struts-el.jar"/>            
              <include name="struts-menu-2.4.2.jar"/>            
              <include name="acegi-security-1.0.2.jar"/>            
              <include name="activation.jar"/>            
              <include name="antlr.jar"/>            
              <include name="antlr-2.7.6.jar"/>            
              <include name="asm.jar"/>            
              <include name="aspectjweaver-1.5.2.jar"/>            
              <include name="cglib-2.1.3.jar"/>            
              <include name="commons-beanutils.jar"/>            
              <include name="commons-codec-1.3.jar"/>            
              <include name="commons-collections.jar"/>            
              <include name="commons-dbcp.jar"/>            
              <include name="commons-digester.jar"/>            
              <include name="commons-fileupload.jar"/>            
              <include name="commons-io.jar"/>    
              <include name="commons-lang.jar"/>            
              <include name="commons-logging-1.1.jar"/>            
              <include name="commons-pool.jar"/>            
              <include name="commons-validator.jar"/>            
              <include name="displaytag-1.1.jar"/>            
              <include name="dom4j-1.6.1.jar"/>            
              <include name="dwr.jar"/>            
              <include name="ehcache-1.2.3.jar"/>            
              <include name="itext-1.4.jar"/>            
              <include name="jakarta-oro.jar"/>            
              <include name="jstl.jar"/>            
              <include name="jta.jar"/>            
              <include name="log4j-1.2.11.jar"/>            
              <include name="mail.jar"/>            
              <include name="oscache-2.3.2.jar"/>            
              <include name="mysql-connector-java-5.0.3-bin.jar"/>            
              <include name="sitemesh-2.2.1.jar"/>            
              <include name="standard.jar"/>            
              <include name="urlrewrite-3.0-beta.jar"/>            
              <include name="velocity-1.4.jar"/>            
              <include name="velocity-tools-view-1.1.jar"/>            
          </fileset>
          <fileset dir="${prjlib.dir}/servletapi-2.3">
              <include name="servletapi-2.3.jar"/>
          </fileset>        
      </path>   
      <target name="usage">
          <echo message=""/>
          <echo message="Spring JPetStore build file"/>
          <echo message="------------------------------------------------------"/>
          <echo message=""/>
          <echo message="Available targets are:"/>
          <echo message=""/>
          <echo message="clean      --> Clean output dirs"/>
          <echo message="build      --> Compile main Java sources and copy libraries"/>
          <echo message="warfile --> Build the web application archive"/>
          <echo message="all        --> Clean, build, warfile"/>
          <echo message=""/>
      </target>   
      <target name="clean" description="Clean output dirs (build, weblib, dist)">
          <delete dir="${build.dir}"/>
          <delete dir="${weblib.dir}"/>
          <delete dir="${war.dir}"/>
          <delete dir="${dist.dir}"/>
          <delete file="client/${name}.jar"/>
      </target>
      <target name="build" description="Compile main source tree java files into class files, generate jar files">
          <mkdir dir="${build.dir}"/>
          <mkdir dir="${war.dir}"/>

<javac destdir="${build.dir}" source="1.3" target="1.3" debug="true"
                  deprecation="false" optimize="false" failonerror="true">
              <src path="${src.dir}"/>
              <classpath refid="master-classpath"/>
          </javac>

<mkdir dir="${weblib.dir}"/>
          <mkdir dir="${war.dir}/WEB-INF/classes"/>

<jar jarfile="${weblib.dir}/${name}.jar" compress="true" basedir="${build.dir}"/>

<copy todir="${war.dir}" preservelastmodified="true">
              <fileset dir="${webcontent.dir}">
                  <include name="**/**"/>
                  <include name="**.**"/>
              </fileset>
          </copy>

<copy todir="${war.dir}/WEB-INF/classes" preservelastmodified="true">
              <fileset dir="${src.dir}">
                  <include name="*.xml"/>
                  <include name="**/*.properties"/>
                  <include name="**/*.vm"/>
                  <exclude name="**/.*"/>
              </fileset>
          </copy>        
       
          <copy file="${weblib.dir}/${name}.jar" tofile="${client.dir}/${name}.jar"/>
      </target>

<target name="dist" depends="warfile">
          <!--
              Delegate to warfile target by depending on it. dist is just to offer
              a generic target name across all Spring sample apps that may be used
              for autobuilds testing.
          -->
      </target>

<target name="warfile" depends="build" description="Build the web application archive">
          <mkdir dir="${dist.dir}"/>
          <war warfile="${dist.dir}/${name}.war" basedir="${war.dir}" webxml="${webcontent.dir}/WEB-INF/web.xml">
              <include name="*"/>
              <include name="images/**"/>
              <include name="common/**"/>
              <include name="decorators/**"/>
              <include name="scripts/**"/>
              <include name="styles/**"/>
              <include name="WEB-INF/*.*"/>
              <include name="WEB-INF/lib/**"/>
              <include name="WEB-INF/pages/**"/>
              <include name="WEB-INF/classes/**"/>
              <exclude name="WEB-INF/web.xml"/>
          </war>
      </target>

<target name="all" depends="clean,build,warfile" description="Clean,build,warfile"/>

</project>

在Eclipse中使用Ant

Ant是Java平台下很棒的批处理命令运行程序,能很方便地自己主动完毕编译,測试,打包,部署等等一系列任务,大大提高开发效率。假设你如今还没有開始使用Ant,那就要赶快開始学习使用,使自己的开发水平上一个新台阶。

Eclipse中已经集成了Ant,我们能够直接在Eclipse中运行Ant。

曾经面建立的Helloproject为例,创建下面文件夹结构:

新建一个build.xml,放在project根文件夹下。build.xml定义了Ant要运行的批处理命令。尽管Ant也能够使用其他文件名称,可是遵循标准能更使开发更规范,同一时候易于与别人交流。

通常,src存放Java源文件,classes存放编译后的class文件,lib存放编译和执行用到的全部jar文件,web存放JSP等web文件,dist存放打包后的jar文件,doc存放API文档。

然后在根文件夹下创建build.xml文件,输入下面内容:

<?xml version="1.0"?>
<project name="Hello world" default="doc">

<!-- properies -->
     <property name="src.dir" value="src" />
     <property name="report.dir" value="report" />
     <property name="classes.dir" value="classes" />
     <property name="lib.dir" value="lib" />
     <property name="dist.dir" value="dist" />
<property name="doc.dir" value="doc"/>

<!-- 定义classpath -->
     <path id="master-classpath">
         <fileset file="${lib.dir}/*.jar" />
         <pathelement path="${classes.dir}"/>
     </path>

<!-- 初始化任务 -->
     <target name="init">
     </target>

<!-- 编译 -->
     <target name="compile" depends="init" description="compile the source files">
         <mkdir dir="${classes.dir}"/>
         <javac srcdir="${src.dir}" destdir="${classes.dir}" target="1.4">
             <classpath refid="master-classpath"/>
         </javac>
     </target>

<!-- 測试 -->
     <target name="test" depends="compile" description="run junit test">
         <mkdir dir="${report.dir}"/>
         <junit printsummary="on"
                 haltonfailure="false"
                 failureproperty="tests.failed"
                 showoutput="true">
             <classpath refid="master-classpath" />
             <formatter type="plain"/>
             <batchtest todir="${report.dir}">
                 <fileset dir="${classes.dir}">
                     <include name="**/*Test.*"/>
                 </fileset>
             </batchtest>
         </junit>
         <fail if="tests.failed">
         ***********************************************************
         ****   One or more tests failed!   Check the output ...   ****
         ***********************************************************
         </fail>
     </target>

<!-- 打包成jar -->
     <target name="pack" depends="test" description="make .jar file">
      <mkdir dir="${dist.dir}" />
         <jar destfile="${dist.dir}/hello.jar" basedir="${classes.dir}">
             <exclude name="**/*Test.*" />
             <exclude name="**/Test*.*" />
         </jar>
     </target>

<!-- 输出api文档 -->
     <target name="doc" depends="pack" description="create api doc">
      <mkdir dir="${doc.dir}" />
      <javadoc destdir="${doc.dir}"
             author="true"
             version="true"
             use="true"
             windowtitle="Test API">
             <packageset dir="${src.dir}" defaultexcludes="yes">
                 <include name="example/**" />
             </packageset>
             <doctitle><![CDATA[<h1>Hello, test</h1>]]></doctitle>
             <bottom><![CDATA[<i>All Rights Reserved.</i>]]></bottom>
             <tag name="todo" scope="all" description="To do:" />
         </javadoc>
     </target>
</project>

以上xml依次定义了init(初始化),compile(编译),test(測试),doc(生成文档),pack(打包)任务,能够作为模板。

选中Helloproject,然后选择“Project”,“Properties”,“Builders”,“New…”,选择“Ant Build”:

填入Name:Ant_Builder;Buildfile:build.xml;Base Directory:${workspace_loc:/Hello}(按“Browse Workspace”选择project根文件夹),因为用到了junit.jar包,搜索Eclipse文件夹,找到junit.jar,把它拷贝到Hello/lib文件夹下,并加入到Ant的Classpath中:

然后在Builder面板中钩上Ant_Build,去掉Java Builder:

再次编译,就可以在控制台看到Ant的输出:

Buildfile: F:/eclipse-projects/Hello/build.xml

init:

compile:
        [mkdir] Created dir: F:/eclipse-projects/Hello/classes
        [javac] Compiling 2 source files to F:/eclipse-projects/Hello/classes

test:
        [mkdir] Created dir: F:/eclipse-projects/Hello/report
        [junit] Running example.HelloTest
        [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.02 sec

pack:
        [mkdir] Created dir: F:/eclipse-projects/Hello/dist
          [jar] Building jar: F:/eclipse-projects/Hello/dist/hello.jar

doc:
        [mkdir] Created dir: F:/eclipse-projects/Hello/doc
      [javadoc] Generating Javadoc
      [javadoc] Javadoc execution
      [javadoc] Loading source files for package example...
      [javadoc] Constructing Javadoc information...
      [javadoc] Standard Doclet version 1.4.2_04
      [javadoc] Building tree for all the packages and classes...
      [javadoc] Building index for all the packages and classes...
      [javadoc] Building index for all classes...
      [javadoc] Generating F:/eclipse-projects/Hello/doc/stylesheet.css...
      [javadoc] Note: Custom tags that could override future standard tags:   @todo. To avoid potential overrides, use at least one period character (.) in custom tag names.
      [javadoc] Note: Custom tags that were not seen:   @todo
BUILD SUCCESSFUL
Total time: 11 seconds

Ant依次运行初始化,编译,測试,打包,生成API文档一系列任务,极大地提高了开发效率。将来开发J2EE项目时,还可增加部署等任务。而且,即使脱离了Eclipse环境,仅仅要正确安装了Ant,配置好环境变量ANT_HOME=<Ant解压文件夹>,Path=…;%ANT_HOME%/bin,在命令行提示符下切换到Hello文件夹,简单地键入ant就可以。

一个build.xml实例的更多相关文章

  1. Java eclipse下 Ant build.xml实例详解

    在有eclipse集成环境下ant其实不是很重要,但有些项目需要用到,另外通过eclipse来学习和理解ant是个很好的途径,所以写他demo总结下要点,希望能够帮到大家. 一.本人测试环境eclip ...

  2. 转:Java eclipse下 Ant build.xml实例详解

    在有eclipse集成环境下ant其实不是很重要,但有些项目需要用到,另外通过eclipse来学习和理解ant是个很好的途径,所以写他demo总结下要点,希望能够帮到大家. 一.本人测试环境eclip ...

  3. Java eclipse下 Ant build.xml实例详解 附完整项目源码

    在有eclipse集成环境下ant其实不是很重要,但有些项目需要用到,另外通过eclipse来学习和理解ant是个很好的途径,所以写他demo总结下要点,希望能够帮到大家. 一.本人测试环境eclip ...

  4. Java MyEclipse下Ant build.xml简单实例详解

    一.下载配置ant 1.首先下载ant: http://www.apache.org/ 下载最新的版本2.解压ant 后设置ANT_HOME, PATH中添加ANT_HOME目录下的bin目录(如:A ...

  5. Ant_的最完整build.xml解释

    Ant的概念 Make命令是一个项目管理工具,而Ant所实现功能与此类似.像make,gnumake和nmake这些编译工具都有一定的缺陷,但是Ant却克服了这些工具的缺陷.最初Ant开发者在开发跨平 ...

  6. Java Ant build.xml详解

    1,什么是antant是构建工具2,什么是构建概念到处可查到,形象来说,你要把代码从某个地方拿来,编译,再拷贝到某个地方去等等操作,当然不仅与此,但是主要用来干这个3,ant的好处跨平台   --因为 ...

  7. (转)Java Ant build.xml详解

    1,什么是ant ant是构建工具2,什么是构建概念到处可查到,形象来说,你要把代码从某个地方拿来,编译,再拷贝到某个地方去等等操作,当然不仅与此,但是主要用来干这个3,ant的好处跨平台   --因 ...

  8. Ant之build.xml详解---可用

    Ant的概念 :在Eclipse中使用Ant Ant是Java平台下非常棒的批处理命令执行程序,能非常方便地自动完成编译,测试,打包,部署等等一系列任务,大大提高开发效率. Ant和make命令很像. ...

  9. ANT编译build.xml

    一,体验ant就像每个语言都有HelloWorld一样,一个最简单的应用能让人感受一下Ant1,首先你要知道你要干什么,我现在想做的事情是:编写一些程序编译它们把它打包成jar包把他们放在应该放置的地 ...

随机推荐

  1. Android Otto调研

    这两天对Otto进行了一个简单的调研,发现官网特别简单差点儿没东西,github上给的sample也不是非常好.网上的技术博客也差点儿千篇一律,我就把自己的心得体会写下来吧,如有缘者看见望其少走弯路. ...

  2. Codeforces 456B Fedya and Maths 打表找规律

    Description Fedya studies in a gymnasium. Fedya's maths hometask is to calculate the following expre ...

  3. malloc和new出来的地址都是虚拟地址 你就说内存管理单元怎么可能让你直接操作硬件内存地址!

    malloc的实现与物理内存自然是无关的,内核为每个进程维护一张页表,页表存储进程空间内每页的虚拟地址,页表项中有的虚拟内存页对应着某个物理内存页面,也有的虚拟内存页没有实际的物理页面对应.无论mal ...

  4. 如何使用github来展示自己的网页

    项目文档或者单纯的html页面怎么用github来展示呢? 第一步:新建库 第二步: 上传自己的页面(index.html需在根目录下) 先把git库克隆下来 进入lineShop文件夹,拷贝自己的页 ...

  5. HTML5-1、标签

    本文只是自己学习HTML5时的一些笔记.希望自己能够学好HTML5. 如果有感兴趣的同学.可以互相学习. 我觉得HTML5在未来的开发中站主导地位. 下面开始学习HTML5. 还是从HTML5标签开始 ...

  6. WCF(二)配置文件

    上篇文章中对WCF的配置放到App.config中,这样可以使程序更灵活.更具有扩展性. 下面说下配置文件中各个节点的含义. 服务端: WCF配置文件节点放在<system.serviceMod ...

  7. 手机号获取省份,城市api的使用

    function get_mobile_area($mobile){ header('Content-Type:text/html;charset=gbk'); $url = 'http://life ...

  8. 手机上最简洁的"云笔记"软件

    ❗️注意:该文并不是真的给你介绍各类云笔记的对比 第三方云笔记的缺点 以前用MIUI和Flyme时,自带的记事本很好用,小巧简洁,路上想起什么就写下来,回去后登录网上的个人中心,拿出来加工一下就可以发 ...

  9. CorelDRAW 2017通过智能笔触调整自然地绘制草图

    LiveSketch 工具是CorelDRAW 2017版本中的新增功能,LiveSketch 工具适合快速草图和绘图,可以帮助您加快工作流并使您能够专注于创建流程.该工具并不预填充节点和图柄,而且无 ...

  10. ZBrush 笔刷的基础参数

    ZBrush®中的笔刷基本参数主要包括3个:Draw Size(绘制大小).Focal Shift(焦点衰减)和Z Intensity(深度强度),通常使用这3个基本参数对笔刷进行调整. 在视图文档区 ...