注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

Code@Pig Home

喜欢背着一袋Code傻笑的Pig .. 忧美.欢笑.记忆.忘却 .之. 角落

 
 
 

日志

 
 

[java] ant (1), simple sample  

2009-06-03 00:08:26|  分类: lang_java |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

源于《Java Power Tools》

安装
从官方(http://ant.apache.org)下载最新版.zip,解压好,比如:D:\apache-ant-1.7.0
ANT_HOME = D:\apache-ant-1.7.0
PATH = %ANT_HOME%\bin

使用

Java 项目常用目录结构
src                                   Application source code
test                                  Unit test code
lib                                    Project dependencies
build                                 Any files generated by the build process
build/classes                  Compiled Java classes
build/test-classes            Compiled unit tests
dist                                  Distribution files, such as bundled JAR or WAR files

Ant 简单实例
src/HelloAnt.java
build.xml

---------------------------- build.xml -----------------------------
<?xml version="1.0" ?>
<project name="hello-ant" default="package">

  <target name="init">
    <mkdir dir="build/classes" />
    <mkdir dir="dist" />
  </target>

  <target name="compile" depends="init" description="Compile Java Code">
    <javac srcdir="src" destdir="build/classes" />
  </target>

  <target name="package" depends="compile" description="Generate JAR file">
    <jar destfile="dist/hello-ant.jar" basedir="build/classes" />
  </target>

  <target name="clean" description="Deletes generated directories">
    <delete dir="build" />
    <delete dir="dist" />
  </target>

</project>
---------------------------------------------------------------------
$ ant
Buildfile: build.xml

init:
    [mkdir] Created dir: /home/kasicass/sandbox/java/ant/HelloAnt/build/classes
    [mkdir] Created dir: /home/kasicass/sandbox/java/ant/HelloAnt/dist

compile:
    [javac] Compiling 1 source file to /home/kasicass/sandbox/java/ant/HelloAnt/build/classes

package:
      [jar] Building jar: /home/kasicass/sandbox/java/ant/HelloAnt/dist/hello-ant.jar

BUILD SUCCESSFUL
Total time: 2 seconds
---------------------------------------------------------------------
$ ant clean
Buildfile: build.xml

clean:
   [delete] Deleting directory /home/kasicass/sandbox/java/ant/HelloAnt/build
   [delete] Deleting directory /home/kasicass/sandbox/java/ant/HelloAnt/dist

BUILD SUCCESSFUL
Total time: 0 seconds
---------------------------------------------------------------------
$ ant -projecthelp
Buildfile: build.xml

Main targets:

 clean    Deletes generated directories
 compile  Compile Java Code
 package  Generate JAR file
Default target: package
---------------------------------------------------------------------

2011-02-21 新版ant需要增加 includeanttime="on",否则会有warning。

<javac srcdir="src" destdir="build/classes" includeantruntime="on" />

  评论这张
 
阅读(814)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017