免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2260 | 回复: 0
打印 上一主题 下一主题

Ant使用入门(转)1--高手勿进 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-12-19 10:52 |只看该作者 |倒序浏览
1、下载安装
下载:http://ant.apache.org
需要设置的环境变量:
ANT_HOME:ant的安装目录
JAVA_HOME:jdk的安装目录
PATH:把%ANT_HOME%\bin目录加到path变量,以便于从命令行下直接运行ant
假定ant解压在c:\ant   jdk装d:\j2sdk1.4.0
则在命令行下执行以下命令:
set ANT_HOME=c:\ant
set JAVA_HOME=D:\j2sdk1.4.0
set PATH=%PATH%;c:\ant\bin
2、工程文件目录结构:
一个 ant 工程目录结构:
C:\workspace\ant.test:工程主目录
\src :源程序目录
\build\classes :编译后的 class 文件目录
\lib :开发工程所需要的类库目录,比如开发数据库时所需要的 jdbc lib(这次没用到)
\jar :打包好的 jar 程序目录(这次没用到)
\build.xml :工程配置文件
\build.propertiees:工程资源文件
2、建立工程描述文件和建立工程资源文件
建立工程描述文件build.xml
               
               
               
?xml version="1.0"?>
project default="main" basedir=".">
    echo message="pulling in property files" />
    property file="build.properties" />
    target name="init">
        echo message="init. delete the old class files. and create the new folds." />
        delete dir="${classpath}" />
        mkdir dir="${classpath}" />
    /target>
    target name="compile" depends="init">
        echo message="compile the java source files." />
        javac srcdir="src\hello\ant" destdir="${classpath}" />
    /target>
    target name="main" depends="compile">
        echo message="calling java to run this java project." />
        java classname="hello.ant.HelloAnt">
            classpath>
                pathelement path="${classpath}" />
            /classpath>
        /java>
    /target>
/project>
建立工程资源文件:build.properties
文件内容是下面一行内容:
classpath=build\\classes
4、建立java源文件:
hello.ant.HelloAnt.java
package hello.ant;
public class HelloAnt {
    public static void main(String[] args) {
        System.out.println("hello ant, the first time using ant... it is great.");
    }
}
5、编译:
C:\workspace\ant.test>ant -buildfile build.xml
Buildfile: build.xml
     [echo] pulling in property files
init:
     [echo] init. delete the old class files. and create the new folds.
   [delete] Deleting directory C:\workspace\ant.test\build\classes
    [mkdir] Created dir: C:\workspace\ant.test\build\classes
compile:
     [echo] compile the java source files.
    [javac] Compiling 1 source file to C:\workspace\ant.test\build\classes
main:
     [echo] calling java to run this java project.
     [java] hello ant, the first time using ant... it is great.
BUILD SUCCESSFUL
Total time: 890 milliseconds
C:\workspace\ant.test>
PS: 转http://blog.csdn.net/lx999501/archive/2006/06/30/856024.aspx
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP