Apache Ant安装及使用
转自:http://guiheji.blog.sohu.com/107658245.html
ant是jakarta一个非常好的OpenSource子项目,是基于java的编译工具。下面简单介绍一下在linux环境中如何安装ant:
1.下载
从 http://ant.apache.org/bindownload.cgi 可以下载最新的tar包:apache-ant-1.6.2.tar.gz,如果是windows环境则是zip文件,解压后,在系统环境变量里设置 ANT_HOME为f:/project/tools/apache-ant-1.6.2,并将f:/project/tools/apache- ant-1.6.2/bin目录添加到classpath中,然后就可以使用了
2./l安装,解压到/usrocal下
> tar zxpvf apache-ant-1.6.2.tar.gz
> ln -s apache-ant-1.6.2 ant
3.设置环境
将ANT_HOME设置到当前用户的.bash_profile文件/home/admin/.bash_profile
[admin@tangtang home]$ su - admin
[admin@tangtang home]$ vi .bash_profile
export ANT_HOME=/usr/local/ant
export PATH=/usr/local/ant/bin:$PATH
如果是windows环境,需要设置%ANT_HOME%,并把%ANT_HOME%/bin目录全路径加入到%path%中
4.测试
用ant命令测试运行情况
[admin@tangtang home]$ ant
Buildfile: build.xml does not exist!
Build failed
[admin@tangtang home]$ ant -version
Apache Ant version 1.6.2 compiled on July 16 2004
若出现这样的错误:Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/tools/ant/launch/Launcher
这是linux系统默认安装了一些ant的lib,修改 /etc/ant.conf中 ANT_HOME=/usr/share/ant 为你正确安装ant的地址,如 /usr/local/ant
5、build脚本
如果是在linux环境中,下面是build脚本的一个范例:
#build脚本#! /bin/sh# 进入到上级目录cd `dirname $0`/..# 获取当前目录为PROJECT_HOMEPROJECT_HOME=`pwd`# 设置JAVA_HOMEexport JAVA_HOME=/usr/cyber/java# 得到CLASSPATHCLASSPATH1=$CLASSPATH# 添加CLASSPATHCLASSPATH=${PROJECT_HOME}/webapps/WEB-INF/conf:${PROJECT_HOME}/webapps/WEB-INF/classes:$CLASSPATH# ant build,-buildfile 参数,是使用自定义的build.xml文件,$@是参数数组/usr/local/ant/bin/ant -buildfile ${PROJECT_HOME}/build/build.xml "$@"# build脚本结束
如果是在windows环境中,下面是build.bat脚本的一个范例:
# build.bat # 关闭echo显示@echo off# 设置%JAVA_HOME%if "%JAVA_HOME%"=="" set JAVA_HOME=f:/tools/java# 设置%ANT_HOME%if "%ANT_HOME%"=="" set ANT_HOME=f:/tools/ant# 设置PROJECT_HOMEset PROJECT_HOME = %CD%/..set CLASSPATH_BAK=%CLASSPATH%set CLASSPATH=# 执行build%ANT_HOME%/bin/ant.bat -buildfile ../build/build.xml %1 %2 %3 %4 %5 %6 %7 %8 %9
6、build配置文件
在${PROJECT_HOME}/build目录下面,需要定义两个文件,一个是build.properties,一个是build.xml
build.properties文件定义了build的一些常量
# build.propertiesproject = tangtangversion = 1.1.1# 采用classic编译,即采用ant编译build.compiler = classic# 采用jikes编译#build.compiler = jikes year = 2004debug = onoptimize = ondeprecation = on os = linuxauthor = tangtangemail = syvin_tom@hotmail.comurl = www.tangtang.org company = tangtang.org
build.xml文件是ant编译的主要配置文件,ant功能强大,需要通过相应的配置项来表现。
<?xml version="1.0" encoding="gb2312"?> <!-- Build file for project --> <project name="cyber" default="jar" basedir="."> <property file="${user.home}/.ant.properties" /> <!-- ant build properties --> <property file="build.properties"/> <property name="build.dir" value=".."/> <property name="build.src" value="${build.dir}/webapps/WEB-INF/src/java"/> <property name="build.dest" value="${build.dir}/webapps/WEB-INF/classes"/> <property name="build.lib" value="${build.dir}/webapps/WEB-INF/lib"/> <property name="build.ext" value="./lib"/> <property name="build.tpl" value="${build.dir}/webapps/WEB-INF/templates"/> <property name="build.encoding" value="gb2312"/> <property name="src.java.dir" value="../src/java"/> <property name="javadoc.destdir" value="../docs/api"/> <property name="javadoc.link" value="http://www.tangtang.org/java/docs/api/"/> <property name="final.name" value="${project}-${version}"/> <property name="dist.root" value="${build.dir}/dist"/> <property name="dist.dir" value="${dist.root}/${final.name}"/> <path id="classpath"> <pathelement path="${java.class.path}/"/> <fileset dir="${build.lib}"> <include name="*.jar"/> </fileset> <fileset dir="${build.ext}"> <include name="*.jar"/> </fileset> </path> <property name="classpath" refid="classpath"/> <!-- =================================================================== --> <!-- prints the environment --> <!-- =================================================================== --> <target name="env"> <echo message="build.compiler = ${build.compiler}"/> <echo message="java.home = ${java.home}"/> <echo message="user.home = ${user.home}"/> <!--echo message="java.class.path = ${java.class.path}"/--> <echo message="classpath = ${classpath}"/> </target> <!-- =================================================================== --> <!-- Prepares the build directory --> <!-- =================================================================== --> <target name="prepare" depends="env"> <tstamp/> <filter token="year" value="${year}"/> <filter token="version" value="${version}"/> <filter token="date" value="${DSTAMP}"/> <!-- <mkdir dir="${build.dir}"/> <mkdir dir="${build.dest}"/> <mkdir dir="${build.src}"/> --> <!-- chose a class that's from j2ee.jar --> <available classname="javax.sql.DataSource" property="J2EE.present"> <classpath refid = "classpath"/> </available> </target> <target name="J2EE-error" depends="prepare" unless="J2EE.present"> <echo>************************************************************ J2EE has not been found and is needed for the target** you have chosen**** Since CLASSPATH is an evil idea, just link or drop** a copy of your j2ee.jar into build/lib directory.***********************************************************</echo></target> <target name="init"> <echo> build init build compile </echo> <mkdir dir="${build.dir}/data"/> <mkdir dir="${build.dir}/logs"/> <mkdir dir="${build.dir}/dist"/> </target> <target name="jar" depends="compile"> <mkdir dir="${dist.root}"/> <delete dir="${dist.root}/${project}-${version}.jar"/> <jar jarfile="${dist.root}/${project}-${version}.jar"> <fileset dir="${build.dest}"> <include name="org/tangtang/**"/> <exclude name="org/tangtang/test/**"/> </fileset> </jar> </target> <target name="srcjar" depends="prepare"> <delete dir="${dist.root}/${project}-${version}-src.jar"/> <jar jarfile="${dist.root}/${project}-${version}-src.jar"> <fileset dir="${build.src}"> <include name="org/tangtang/**"/> <include name="org/tangtang/test/**"/> </fileset> </jar> </target> <target name="tpl" depends="env"> <jar jarfile="${dist.root}/${project}-${version}-tpl.jar"> <fileset dir="${build.tpl}"> <include name="tangtang/**"/> </fileset> </jar> </target> <target name="javadocs"> <mkdir dir="${build.dir}/docs/api"/> <javadoc sourcepath="${build.src}" overview="${build.dir}/docs/overview.html" packagenames="org.tangtang.*" destdir="${build.dir}/docs/api" encoding="${build.encoding}" author="true" version="true" use="true" link="${javadoc.link}" windowtitle="${project} ${version} API" doctitle="${project} ${version} API" bottom="Copyright © ${year} tangtang.org. All Rights Reserved." > <tag name="todo" description="To Do:"/> </javadoc> </target> <target name="poolman" depends="prepare"> <jar jarfile="${dist.root}/poolman.jar"> <fileset dir="${build.dest}"> <include name="com/codestudio/**"/> </fileset> </jar> </target> <target name="nightly" depends="prepare"> <tstamp/> <jar jarfile="${dist.root}/nightly/${project}-${version}-${DSTAMP}-src.jar"> <fileset dir="${build.src}"> <include name="org/tangtang/**"/> </fileset> </jar> </target> <target name="compile" depends="prepare"> <mkdir dir="${build.dest}"/> <!-- 检查依赖性 --> <depend srcdir="${build.src}" destdir="${build.dest}" cache="${build.dest}"> <classpath refid="classpath"/> </depend> <javac srcdir="${build.src}" destdir="${build.dest}" debug="${debug}" deprecation="${deprecation}" optimize="${optimize}"> <classpath refid="classpath"/> </javac> </target> <target name="clean"> <delete> <fileset dir="${build.dest}"> <include name="**/*.class"/> </fileset> </delete> </target> <target name="clean_dist"> <delete> <fileset dir="${dist.root}" includes="*"/> </delete> <delete dir="${dist.dir}" quiet="false"/> </target> <target name="deploy" depends="jar"> <mkdir dir="${dist.dir}/data"/> <mkdir dir="${dist.dir}/logs"/> <copy todir="${dist.dir}/bin"> <fileset dir="${build.dir}/bin"> <include name="*"/> </fileset> </copy> <fixcrlf srcdir="${dist.dir}/bin" eol="lf" eof="remove" includes="**/*" excludes="**/*.bat" /> <copy todir="${dist.dir}/conf"> <fileset dir="${build.dir}/conf"> <include name="templates/*"/> <exclude name="*"/> <exclude name="**/*.bak"/> <exclude name="**/bak/**"/> </fileset> </copy> <copy todir="${dist.dir}/build"> <fileset dir="${build.dir}/build"> <include name="*"/> <include name="lib/*"/> <exclude name="**/*.bak"/> <exclude name="**/bak/**"/> </fileset> </copy> <copy todir="${dist.dir}/templates"> <fileset dir="${build.dir}/templates"> <include name="**/*.vm"/> <exclude name="**/*.bak"/> <exclude name="**/bak/**"/> </fileset> </copy> <copy todir="${dist.dir}/webapps/html"> <fileset dir="${build.dir}/webapps/html"> <include name="**/*"/> <exclude name="**/*.bak"/> <exclude name="**/bak/**"/> </fileset> </copy> <copy todir="${dist.dir}/webapps/applet"> <fileset dir="${build.dir}/webapps/applet"> <include name="**/*"/> <exclude name="**/*.bak"/> <exclude name="**/bak/**"/> </fileset> </copy> <copy todir="${dist.dir}/webapps/icons"> <fileset dir="${build.dir}/webapps/icons"> <include name="**/*.gif"/> <include name="**/*.jpg"/> <exclude name="**/*.bak"/> <exclude name="**/bak/**"/> </fileset> </copy> <copy todir="${dist.dir}/webapps/images"> <fileset dir="${build.dir}/webapps/images"> <include name="**/*.gif"/> <include name="**/*.jpg"/> <exclude name="**/*.bak"/> <exclude name="**/bak/**"/> </fileset> </copy> <copy todir="${dist.dir}/webapps/WEB-INF/"> <fileset dir="${build.dir}/webapps/WEB-INF/"> <include name="**/*"/> <exclude name="classes/**"/> <exclude name="conf/*"/> <exclude name="src/**"/> </fileset> </copy> <jar jarfile="${dist.root}/${project}-${version}-war.jar"> <fileset dir="${dist.dir}"> <include name="**/*"/> </fileset> </jar> </target> <target name="conf"> <delete> <fileset dir="${build.dir}/conf" includes="*"/> <fileset dir="${build.dir}/webapps/WEB-INF/conf" includes="*"/> </delete> <filter filtersfile="deploy.properties"/> <copy todir="${build.dir}/conf" filtering="true"> <fileset dir="${build.dir}/conf/templates"> <include name="*"/> </fileset> </copy> <copy todir="${build.dir}/webapps/WEB-INF/conf" filtering="true"> <fileset dir="${build.dir}/webapps/WEB-INF/conf/templates"> <include name="*"/> </fileset> </copy> </target> </project>
Apache Ant安装及使用相关推荐
- Apache Ant安装 验证
1.下载Apache Ant 去官网下载ant,官网地址:http://ant.apache.org/ 我下载的是apache-ant-1.10.1-bin.zip 直接解压,放到制定目录下,如C:\ ...
- [ANT]apache ant 安装说明
准备工作 下载地址:https://downloads.apache.org/ant/binaries/ JDK: 1.8 官网: https://ant.apache.org/manual/inde ...
- apache ant 安装_SAP Hybris使用recipe进行安装时,是如何执行ant命令的?
打开Hybris安装文件夹下的recipes,随便打开一个recipe的build.gradle文件,发现使用了installer-platform-plugin和installer-addon-pl ...
- apache ant 安装_Jmeter+ Ant+jenkins 接口自动化框架实现
一.文件配置 •编写jmeter脚本 •上传jmx脚本到jmeter目录下,新建一个Loadtest目录, •在Tomcat webapp 文件夹下面新建报告输出文件夹testReport: •将jm ...
- Apache Ant 的安装
从apache的官网下载安装包apache-ant-1.9.3-bin.zip,直接解压到某个工作目录(example: D:\Tools\) 下,然后添加环境变量ANT_HOME, 设置其值为: D ...
- linux ant安装jar,ant打JAR、WAR包
1. ant安装 上官网下载ANT:http://ant.apache.org/bindownload.cgi 解压出来,添加系统变量ANT_HOME,并把ANT路径加入系统变量Path中 在命令行中 ...
- Apache Ant运行时Unable to locate tools.jar解决方法
下载Apache Ant 一.解压ant安装包在D:\ant下 二.环境变量配置 ANT_HOME D:\ant\apache-ant-1.9.0 CLASSPATH ;%ANT_HOME%lib; ...
- ant安装(for linux)
一. 下载 从http://ant.apache.org/bindownload.cgi可以下载最新的tar包:apache-ant-1.8.4-bin.tar.gz 二. 解压安装 将ant的tar ...
- ant 安装及基础教程 !
这篇文章主要介绍了ant使用指南详细入门教程,本文详细的讲解了安装.验证安装.使用方法.使用实例.ant命令等内容,需要的朋友可以参考下 一.概述 ant 是一个将软件编译.测试.部署等步骤联系在一起 ...
最新文章
- python列表元素修改_python – 如何修改列表中列表中的元素
- 杀手级AI补代码工具问世,支持23种语言及5种主流编辑器,程序员沸腾了
- MySQL事务的不可重复读
- 设备服务器停止运行吗,服务器已停止响应是怎么回事
- rhel5下限值用户使用su切换身份
- 85、交换机安全MAC层***配置实验之Port-Security
- 论文浅尝 | 利用 KG Embedding 进行问题回答
- android slidingdrawer 方向,如何使Android SlidingDrawer从左侧滑出?
- 【ECCV2020】完整论文集part2
- portal认证 只能重定向80和443请求_华为防火墙内置Portal认证报文交互
- windows之2012安装vs2017编译环境失败
- C++中-运算符与.运算符的具体使用
- ECSHOP始终显示全部分类方法
- 君子不器 (器就不是君子)
- (兼职月赚两万?)程序员如何接私活? 如何让自己的知识变现?
- 苹果手机电池怎么保养_手机电池损耗检测,电池修复软件
- 区块链≠分布式账本,别再傻傻分不清
- DC电源插头工作原理
- RFID信息系统数据安全对策分析
- Dubbo剖析-粘包与半包问题(一)