首页 技术 正文
技术 2022年11月9日
0 收藏 789 点赞 2,256 浏览 2660 个字

ant是一个脚本构建工具,可能就是持续集成里面所需要的构建工具。

如果使用eclipse,里面会自带有ant工具,不需要再安装了,创建一个build.xml(或者其他的名字都可以),使用ant来运行就可以了

如果使用的命令行来运行ant,需要安装的步骤如下:

(1)下载ant,解压,无需安装过程。

(2)将ant的bin目录加入到系统的环境变量path中。

(3)运行ant,可以查看是否加成功了。

(4)在cmd中,将目录切换到工程所在的build.xml目录下,运行ant(这里默认为build.xml文件,还可以自己制定需要的文件)

关于build.xml文件的目录结构

<project name=”**”>

<property name=”src” value=”test” />

<path id=”classpath1.path”>
<fileset dir=”${lib.dir}”>

<property name=”dest” value=”classes” />

<property name=”lib.dir” value=”lib”/>

<include name=”*.jar” />

</fileset>

<pathelement location=”${src}” />

<pathelement location=”${dest}”/>
</path>

<!– 定义一些初始化的操作 !–>

<target name=”init”>
    <delete verbose=”true” includeemptydirs=”true”>
    <fileset dir=”${dest}”>
        <include name=”**/*”/>
    </fileset>
</delete>
<mkdir dir=”${dest}” />
</target>

<!–编译 !–>

<target name=”compile” depends=”init”>
<javac srcdir=”${src}” destdir=”${dest}” classpathref=”classpath1.path”/>
<echo message=”${TIME}” />
</target>

<!–接下来有一些你需要做的事情,比如打包部署,或者运行一个程序等 !–>

</project>

一些需要记录的东西:

(1)运行一个java程序的定义:

<target name=”sendmail” depends=”compile”>
   <java classname=”com.sogou.maps.testApi.Integration” classpathref=”classpath1.path”>
       <classpath path=”${dest}”></classpath>
       <arg value=”${basedir}/${TIME}/emailable-report.html”></arg>
   </java>
</target>

如果引用了第三方的包,那么需要在classpathref中定义,否则会提示错误信息。

(2)定义一个时间戳

<tstamp> 
         <format property=”TIME” pattern=”yyyyMMdd-hhmm” locale=”en,UK”/> 
    </tstamp>

只要定义了这个,就定义了三个参数:DSTAMP,TSTAMP,TODAY,在下面的内容中就可以使用${DSTAMP}等了。在上面我们定义了自己的参数TIME,可以使用。这个时间戳在整个build过程中是不变的。

(3)在命令行里运行的参数

命令行选项总结:
ant [options] [target [target2 [target3] …]]
Options:
-help print this message
-projecthelp print project help information
-version print the version information and exit
-quiet be extra quiet
-verbose be extra verbose
-debug print debugging information
-emacs produce logging information without adornments
-logfile file use given file for log output
-logger classname the class that is to perform logging
-listener classname add an instance of class as a project listener
-buildfile file use specified buildfile
-find file search for buildfile towards the root of the filesystem and use the first one found
-Dproperty=value set property to value

(4)一些ant自带的内置变量

os.name:       操作系统的名称。

basedir: 项目引用的根路径。

ant.home:     Ant工具的根目录位置。

ant.file: 构件文件的绝对路径。

ant.version:   ant的版本信息。

ant.java.version: ant检测到的JVM版本。

ant.project.name: 当前执行的项目名称及信息。

java.version: Java的版本信息。

java.home:    Java的根目录位置。

java.class.path: Java类库的文件的位置。

line.separator:   换行符.

(5)编译的时候如果在windows下面使用命令行来运行ant的话,工程使用UTF-8,编译会有编码错误。需要设定编译的编码

<target name=”compile” depends=”init”>
<javac srcdir=”${src}” destdir=”${dest}” classpathref=”classpath1.path”>
<compilerarg line=”-encoding UTF-8″></compilerarg>
</javac>
<echo message=”${TIME}” />
</target>

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,088
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,564
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,413
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,186
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,822
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,905