日期:2014-05-16  浏览次数:20705 次

我使用过的Linux命令之ant - 强大的Java开发构建工具

我使用过的Linux命令之ant - 强大的Java开发构建工具

本文链接:http://codingstandards.iteye.com/blog/801506 ? (转载请注明出处)

?

用途说明

ant严格说来,ant其实并非原生的Linux命令,但它 是一个使用广泛、功能强大的跨平台 构建工具程序,尤其是进行Java开发时,许多开源的Java项目都使用ant作为构建工具。ant命令一般情况下使用当前目录下的build.xml文件作为构建用的配置文件,具体配置文件怎么编写本文不讨论,这个绝对可以展开成一个系列。本文主要演示一下在Linux下怎么安装ant,以及常用方式等。

官方站点:http://ant.apache.org/

当前版本:1.8.1

安装步骤

安装条件

必须安装有jdk。下面是官方网站提供的两个注意事项:

Note: If a JDK is not present, only the JRE runtime, then many tasks will not work.

Note: Ant 1.8.* works with jdk1.4 and higher, Ant 1.7.* works with jdk1.3 and higher, Ant 1.6.* works with jdk 1.2 and higher, Ant 1.2 to Ant 1.5.* work with jdk 1.1 and higher.

下载文件

如果Linux机器不能上公网

第一步,获取安装包。到http://ant.apache.org/bindownload.cgi 下载apache-ant-1.8.1-bin.tar.gz

第二步,上传到Linux机器。使用sftp或者ftp。

?

[root@bbqztweb setup]# ls -l

-rw-r--r--??? 1 root???? root????? 8264796? 5月? 1 06:03 apache-ant-1.8.1-bin.tar.gz

如果Linux机器能上公网

可直接使用wget获取安装包,使用人人网上的镜像文件比较快。如下所示:

[root@bbqztweb setup]# wget http://labs.renren.com/apache-mirror//ant/binaries/apache-ant-1.8.1-bin.tar.gz
--21:08:03--? http://labs.renren.com/apache-mirror//ant/binaries/apache-ant-1.8.1-bin.tar.gz
?????????? => `apache-ant-1.8.1-bin.tar.gz'
正在解析主机 labs.renren.com... 123.129.232.121
Connecting to labs.renren.com|123.129.232.121|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:8,264,796 (7.9M) [application/x-gzip]

100%[========================================================================================>] 8,264,796??? 376.27K/s??? ETA 00:00

21:08:30 (314.87 KB/s) - `apache-ant-1.8.1-bin.tar.gz' saved [8264796/8264796]

?

[root@bbqztweb setup]# ls -l

-rw-r--r--??? 1 root???? root????? 8264796? 5月? 1 06:03 apache-ant-1.8.1-bin.tar.gz

?

解压文件

[root@bbqztweb setup]# tar zxf apache-ant-1.8.1-bin.tar.gz
[root@bbqztweb setup]# mkdir -p /opt/apache
[root@bbqztweb setup]# mv apache-ant-1.8.1 /opt/apache
[root@bbqztweb setup]# ls /opt/apache
apache-ant-1.8.0? apache-ant-1.8.1? apache-tomcat-6.0.26? axis2-1.5.1

设置环境

编辑文件/etc/profile.d/ant.sh

[root@web jlib]# vim /etc/profile.d/ant.sh

?

#! /bin/sh

# 2007.01.22 ant 2010.03.18 2010.06.28
if [ -d /opt/apache/apache-ant-1.8.1 ]; then
        export ANT_HOME=/opt/apache/apache-ant-1.8.1
elif [ -d /opt/apache/apache-ant-1.8.0 ]; then
        export ANT_HOME=/opt/apache/apache-ant-1.8.0
elif [ -d /usr/apache/apache-ant-1.7.1 ]; then
        export ANT_HOME=/usr/apache/apache-ant-1.7.1
elif [ -d /usr/apache/apache-ant-1.7.0 ]; then
        export ANT_HOME=/usr/apache/apache-ant-1.7.0
elif [ -d /usr/apache/apache-ant-1.6.5 ]; then
        export ANT_HOME=/usr/apache/apache-ant-1.6.5
fi
if [ $ANT_HOME ]; then
        [ $PATH ] && PATH=$ANT_HOME/bin:$PATH || PATH=$ANT_HOME/bin
fi
?

重新登录

[root@web jlib]# echo $ANT_HOME
/opt/apache/apache-ant-1.8.1
[root@web jlib]# echo $PATH
/usr/kerberos/sbin:/usr/kerberos/bin:/opt/apache/apache-ant-1.8.1/bin:/usr/java/jdk1.6.0_20/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
[root@web jlib]# ant
Buildfile: build.xml does not