Ant是一个Apache基金会下的跨平台的构件工具,可以实现自动构建和部署,大多数用于JAVA环境中的软件开发

Ant

官网:http://ant.apache.org/
官方文档:http://ant.apache.org/manual/index.html
下载:http://ant.apache.org/bindownload.cgi
apache-ant-1.9.9-bin.zip官方下载
apache-ant-1.9.9-bin.zip本地下载

ANT流程
jar包这个部分步骤是为下面编译增量包做准备的,因为增量包导出的增量文件,它依赖于整个项目的其他代码,如果没有这些代码的支持是编译不通过。然而又不能直接通过diff得到增量的class,所以只能导出增量文件后,通过引用全部工程的代码的class再进行编译即可

环境:
   centos 7.2
   jdk version 1.7.0_79
   ant version 1.9.9

如果报这个错,说明是服务器上目前的JDK版本不正确

1
2
3
4
5
6
[root@localhost local]# ant --version
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/apache/tools/ant/launch/Launcher : Unsupported maj
or.minor version 52.0 at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)

官方说明

1
2
3
The Apache Ant team currently maintains two lines of development. The 1.9.x releases require Java5 at runtime and 1.10.x requires Java8 at runtime. Both lines are based off of Ant 1.9.7 and the 1.9.x releases are mostly bug fix releases while additional new features are developed for 1.10.x. We recommend using 1.10.x unless you are required to use versions of Java prior to Java8 during the build process.
Currently, Apache Ant 1.9.9 and 1.10.1 are the best available versions, see the release notes.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@localhost ~]# unzip apache-ant-1.9.9-bin.zip -d /usr/local/
[root@localhost ~]# tail -2 /etc/profile
export ANT_HOME="/usr/local/apache-ant-1.9.9"
export PATH="$JAVA_HOME"/bin:"$ANT_HOME"/bin:$PATH
[root@localhost ~]#
[root@localhost ~]# echo $ANT_HOME
/usr/local/apache-ant-1.9.9
[root@localhost ~]#
[root@localhost ~]# java -version
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)
[root@localhost ~]#
[root@localhost ~]# ant -version
Apache Ant(TM) version 1.9.9 compiled on February 2 2017
[root@localhost ~]#

因为这里没有build.xml,所以会报错

1
2
3
4
[root@localhost ~]# ant
Buildfile: build.xml does not exist!
Build failed
[root@localhost ~]#

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#手动建一个build.xml文件
[root@localhost ~]# cat build.xml
<?xml version="1.0" encoding="GBK"?>
<project name="测试脚本" default="copyfile" basedir="." >
<target name="copyfile">
<copy file="/root/a.txt" todir="/tmp/" overwrite="true" />
</target>
</project>
[root@localhost ~]#
#新建一个文件a.txt
[root@localhost ~]# ll /root/a.txt
-rw-r--r-- 1 root root 21 Jun 19 05:43 /root/a.txt
[root@localhost ~]# cat /root/a.txt
My filename is a.txt
[root@localhost ~]#
#执行ant命令
[root@localhost ~]# ant
Buildfile: /root/build.xml
copyfile:
[copy] Copying 1 file to /tmp
BUILD SUCCESSFUL
Total time: 0 seconds
[root@localhost ~]#
[root@localhost ~]# ll /tmp/a.txt
-rw-r--r-- 1 root root 21 Jun 19 05:43 /tmp/a.txt
[root@localhost ~]# cat /tmp/a.txt
My filename is a.txt
[root@localhost ~]#

ANT+Jenkins

ant_jenkins_plugin
“Jenkis”— “系统管理”— “Global Tool Configuration”— “Ant”
ant_jenkins
ant_jenkins
ant_jenkins
ant_jenkins

这里没有ANT项目就不跑Jenkins了哈

关于ant的一些用法,参考:http://www.blogjava.net/amigoxie/archive/2007/11/09/159413.html
关于ANT打包的可以参考:http://www.cnblogs.com/hoojo/p/ant_increment_svn_diff_diffSummarize.html


本文出自”Jack Wang Blog”:http://www.yfshare.vip/2017/06/19/Ant/