初学ant
来源:互联网 发布:macos 配置软件 编辑:程序博客网 时间:2024/06/04 00:20
ant是一款基于java的构建工具,随着应用程序的生成过程变得更加复杂,确保在每次生成期间都使用精确相同的生成步骤,同时实现尽可能多的自动化,以便及时产生一致的生成版本。
下载和安装
1.下载地址,http://ant.apache.org/bindownload.cgi
2.安装. 设置环境变量ANT_HOME到下载文件的解压目录,在path中添加ant的命令,即:
%ANT_HOME%/bin(windows).同时也要设置JAVA_HOME。
3.(可选的)在ant安装目录运行命令:ant -f fetch.xml -Ddest=system,去获得一些ant任务的依赖包,如果不执行,一些依赖的ant任务是无效的。
4.检验。 在命令行键入"ant"命令,如果出现
Buildfile: build.xml does not exist!Build failed说明安装成功。
做个小例子:
<!--目的是练习ant,方式是将下面这个项目的class文件打成jar,然后将整个项目打成war包项目目录结构,这是一个eclipse的web工程目录结构,当然也可以不必是这种结构。这主要是为了练习,不想去凑web工程需要的各个部分,就直接用这个了。 exam -build -存放class文件 -business 源文件夹 -common 源文件夹 -test 测试文件夹 -WebContent -app js文件夹 -resource 存放css,image等 -META-INF -WEB-INF -web.xml -classes 存放classes -lib 存放jar -index.html --><project name="MyProject" default="buildwar" basedir="D:\otherwp\exam"> <description> simple example build file </description> <!-- set global properties for this build --> <property name="build" location="build"/> <property name="business" location="business"/> <property name="common" location="common"/> <property name="test" location="test"/><property name="destination" location="H:\ant\exam"/><property name="tomcatlib" location="D:\apache-tomcat-7.0.26\lib"/><path id="lib"><fileset dir="${basedir}\WebContent\WEB-INF\lib"><include name="**/*.jar"/></fileset><fileset dir="${tomcatlib}"><include name="**/*.jar"/></fileset><!--<pathelement path=""/> <pathelement location=""/> location属性指定了相对于project基目录的一个文件和目录,而path属性接受逗号或分号分隔的一个位置列表。path属性一般用作预定义的路径也可通过<fileset>元素指定路径。构成一个fileset的多个文件加入path-like structure的顺序是未定的。--> </path> <target name="clean"> <!-- Create the time stamp --> <tstamp/> <!-- Create the build directory structure used by compile --> <delete dir="${build}\classes"/> <delete dir="${destination}"/> </target> <target name="compile" depends="clean" description="compile the source " > <!-- Compile the java code from ${src} into ${build} --> <mkdir dir="${build}\classes"/> <!--打印lcasspath--> <property name="myclasspath" refid="lib"/> <echo message ="${myclasspath}"/> <!--编译多个目录,目录之间用冒号分隔--> <javac srcdir="${business}:${common}:${test}" destdir="${build}\classes"target="1.5" debug="on"classpath="${lib}"optimize="true"encoding="UTF-8" ><classpath refid="lib"></classpath> </javac><!--注意:我测试的时候,将classpath以属性的方式放在javac节点中不行,以javac子节点的形式可以,这情况正常吗?懂的还望指点一二--><!--试试在javac节点使用属性 classpathref="lib" --><!--destdir:指明编译过后存放位置includes:必须包括的文件模式的列表,以逗号或空格分隔。如果忽略,将包括所有文件。excludes:必须排除的文件模式的列表,以逗号或空格分隔。如果忽略,将不排除任何文件。encoding: 指定编译文件的编码target:根据特定的vm版本生成class文件optimize:指出是否应该用优化方式编译源代码,默认为 off。 debug: 是否产生调试信息,默认off。 ...--> </target> <target name="dist" depends="compile" description="generate the distribution" > <!-- Create the distribution directory --> <mkdir dir="${destination}"/> <mkdir dir="${destination}/lib"/> <!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file --> <jar jarfile="${destination}/lib/MyProject-${DSTAMP}.jar" basedir="${build}\classes"/> </target><!--只要你有web工程的各个组成部分(webxml,lib,classes),就可以打成war包--><target name="buildwar" depends="dist"> <mkdir dir="${destination}/war"/> <war destfile ="${destination}/war/WebTest.war" webxml ="${basedir}/WebContent/WEB-INF/web.xml"> <!-- 拷贝WebRoot 下文件夹--> <fileset dir ="${basedir}/WebContent"> <exclude name="WEB-INF;META-INF"/> </fileset> <!-- 拷贝lib 目录下的jar 包--> <lib dir ="${basedir}/WebContent/WEB-INF/lib"/> <!-- 拷贝build/classes 下的class 文件--> <classes dir ="${build}\classes"/> </war></target> </project>
- 初学Ant.
- 初学ant
- 初学maven(4)-使用maven ant task实现非标准打包
- <程序猿--艰难历程>之Apache Ant 初学入门一
- 初学maven(4)-使用maven ant task实现非标准打包
- ANT初学入门之一:基本概念、安装与配置
- ant
- ant
- Ant
- ant
- ANT
- ANT
- ant
- ant
- ant
- ant
- ant
- ANT
- STS Attractive Features
- 流媒体使用的传输协议
- 不出门也能拍好证件照
- xampp中mysql遇到的一系列问题
- Hadoop---在HDFS集群基础上搭建Map/Reduce集群
- 初学ant
- 在windowless=true的条件下让silverlight输入中文
- AutoPostBack属性
- HTTP协议的状态码
- HDU3716 Jenga
- NS2仿真过程中需要的语言及基本组件
- C++中的new与delete总结
- linux下C语言文件的创建打开和关闭
- ios中设置N秒后执行一个函数