1、windows下配置ant运行环境,定义JAVA_HOME、ANT_HOME、PATH中加入%JAVA_HOME%\bin和%ANT_HOME%\bin;ant使用1.6.5版本或以上,jdk使用1.5或以上;

2、java工程目录推荐按照如下设置,如果是普通的应用工程,则
App
-src
-config
-test
-lib
-so/*.*
-dll/*.*
-*.bat
-*.sh


如果是web应用工程,则
webApp
-src
-web
-config
-test
-lib


3、以如下build.xml为模板,重新编写ant脚本,程序员只要定义好外部类路径和内部类路径即能正常编译
xml version ="1.0" encoding ="UTF-8" ?>
< project default ="release" name ="test" >
  
   < property name ="build.compiler" value ="org.eclipse.jdt.core.JDTCompilerAdapter" />
  
   < property name ="src" value ="./src" />
  
   < property name ="web" value ="./web" />
  
   < property name ="config" value ="./config" />
  
   < property name ="author" value ="cuiyingfeng" />
  
   < property name ="version" value ="0.9.0.0" />
  
   < property name ="type" value =".jar" />
  
   < property name ="encoding" value ="UTF-8" />
   < property name ="sourcejdk" value ="1.5" />
   < property name ="targetjdk" value ="1.5" />
  
   < path id ="ref-classpath" >
   path >
  
   < path id ="dep-classpath" >
     < fileset dir ="../../Lib" >
       < include name ="activation.jar" />
       < include name ="axis.jar" />
       < include name ="commons-logging*.jar" />
       < include name ="commons-discovery*.jar" />
       < include name ="commons-dbcp*.jar" />
       < include name ="commons-pool*.jar" />
       < include name ="jaxrpc*.jar" />
       < include name ="log4j*.jar" />
       < include name ="mail*.jar" />
       < include name ="asm*.jar" />
       < include name ="cglib*.jar" />
       < include name ="aspect*.jar" />
       < include name ="spring*.jar" />
       < include name ="saaj*.jar" />
       < include name ="wsdl4j*.jar" />
     fileset >
     < fileset dir ="../Common/release/lib" >
       < include name ="*.jar" />
     fileset >
   path >
   < import file ="./build_common.xml" />
project >

4、dos下cd进工程目录,然后ant,工程将自动编译,编译成功后,将在工程目录下产生一个build和release目录,其中build目录中存放编译中间结果,release目录中存放的是可以直接安装部署的java应用和web应用。执行ant clean将会删除当前工程目录下的build和release目录。

总结:该模板封装了使用ant进行编译的细节,只暴露了一些工程属性的设置给使用者,实际应用中,程序员不需要考虑ant语法,只需要关注部分工程属性就能很方便地对java工程进行发布。该模板非常实用,基本不需要修改就可以直接在大多数J2EE项目中使用。

ps:build_common.xml可以在我的资源中下载,定价较高,慎下!