[root@localhost ~]# yum install epel-release -y
[root@localhost ~]# rpm -qa ant
[root@localhost ~]# ant
-bash: ant: command not found
[root@localhost ~]# yum install ant
[root@localhost ~]# ant -version
Apache Ant(TM) version 1.9.2 compiled on June 10 2014
[root@localhost ~]# java -version
openjdk version “1.8.0_161”
OpenJDK Runtime Environment (build 1.8.0_161-b14)
OpenJDK 64-Bit Server VM (build 25.161-b14, mixed mode)
[root@localhost ~]# ant
Buildfile: build.xml does not exist!
Build failed
[root@localhost ~]# ant –help
/bin/ant [script options] [options] [target [target2 [target3] ..]]
Script Options:
–help, –h print this message and ant help
–noconfig suppress sourcing of /etc/ant.conf,
$HOME/.ant/ant.conf, and $HOME/.antrc
configuration files
–usejikes enable use of jikes by default, unless
set explicitly in configuration files
–execdebug print ant exec line generated by this
launch script
ant [options] [target [target2 [target3] …]]
Options:
-help, -h print this message
-projecthelp, -p print project help information
-version print the version information and exit
-diagnostics print information that might be helpful to
diagnose or report problems.
-quiet, -q be extra quiet
-silent, -S print nothing but task outputs and build failures
-verbose, -v be extra verbose
-debug, -d print debugging information
-emacs, -e produce logging information without adornments
-lib <path> specifies a path to search for jars and classes
-logfile <file> use given file for log
-l <file> ”
-logger <classname> the class which is to perform logging
-listener <classname> add an instance of class as a project listener
-noinput do not allow interactive input
-buildfile <file> use given buildfile
-file <file> ”
-f <file> ”
-D<property>=<value> use value for given property
-keep-going, -k execute all targets that do not depend
on failed target(s)
-propertyfile <name> load all properties from file with -D
properties taking precedence
-inputhandler <class> the class which will handle input requests
-find <file> (s)earch for buildfile towards the root of
-s <file> the filesystem and use it
-nice number A niceness value for the main thread: 1 (lowest) to 10 (highest); 5 is the default
-nouserlib Run ant without using the jar files from ${user.home}/.ant/lib
-noclasspath Run ant without using CLASSPATH
-autoproxy Java1.5+: use the OS proxy settings
-main <class> override Ant’s normal entry point
[root@localhost ~]# mkdir -p example/src/com/testing
[root@localhost ~]# cd example/
[root@localhost example]# vim build.xml
<?xml version=”1.0″ ?>
<project name=”HelloWorld” default=”compress”>
<target name=”init”>
<mkdir dir=”build/classes” />
<mkdir dir=”dist” />
</target>
<target name=”compile” depends=”init”>
<javac srcdir=”src” destdir=”build/classes” />
</target>
<target name=”compress” depends=”compile”>
<jar destfile=”dist/HelloWorld.jar” basedir=”build/classes” />
</target>
<target name=”execute” depends=”compile”>
<java classname=”com.testing.helloworld.HelloWorld” classpath=”build/classes” />
</target>
<target name=”clean”>
<delete dir=”build” />
<delete dir=”dist” />
</target>
</project>
[root@localhost example]# ant
Buildfile: /root/example/build.xml
init:
[mkdir] Created dir: /root/example/build/classes
[mkdir] Created dir: /root/example/dist
compile:
[javac] /root/example/build.xml:10: warning: ‘includeantruntime’ was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
compress:
[jar] Building MANIFEST-only jar: /root/example/dist/HelloWorld.jar
BUILD SUCCESSFUL
Total time: 0 seconds
[root@localhost example]# tree .
.
|– build
| `– classes
|– build.xml
|– dist
| `– HelloWorld.jar
`– src
`– com
`– testing
6 directories, 2 files
[root@localhost example]# ls -l
total 4
drwxr-xr-x. 3 root root 21 Mar 8 10:17 build
-rw-r–r–. 1 root root 622 Mar 8 10:16 build.xml
drwxr-xr-x. 2 root root 28 Mar 8 10:17 dist
drwxr-xr-x. 3 root root 17 Mar 8 10:15 src
For more info on how to write targets please refer
https://ant.apache.org/manual/using.html
https://ant.apache.org/manual/tutorial-writing-tasks.html
