Apache Ant
Apache Ant
|
|
---|---|
![]() |
|
Basic data
|
|
developer | Apache Software Foundation |
Publishing year | July 19, 2000 (version 1.1) |
Current version |
1.10.8 ( March 13, 2020 ) |
operating system | Platform independence |
programming language | Java |
category | Build management tool |
License | Apache license, version 2.0 |
ant.apache.org |
Apache Ant ( English for ant ) is a program written in Java for the automated generation of executable computer programs from source texts .
It fulfills the same purpose as the very popular make program , namely the automated creation of installable software packages from existing source code, libraries and other files. Ant is open source , started as part of the Jakarta project and is now an Apache top-level project. Ant is an apronym and stands for “Another Neat Tool” (English for “Another pretty tool”). The first version was developed by James Duncan Davidson , who needed a tool like make for Java in 1999 while he was developing the first J2EE reference implementation. Davidson is also considered the father of Jakarta Tomcat . For him, the name “Ant” means that as a small program, just like the little ants, it can achieve great things.
description
In contrast to make , Ant is implemented in Java and therefore requires a Java runtime environment (JRE) to run.
Terms
Ant is controlled by an XML file, the so-called build file . It is called by default build.xml
. A project is defined in the build file . This is the root element of the XML file. A software project should have exactly one build file and therefore exactly one Ant project.
The Ant-Project contains Targets . These are comparable to functions in programming languages and can be specifically called from outside, for example by the developer via the command line or the development environment . The targets in their entirety should cover all activities that arise when working with a software project. Dependencies can be defined between the targets according to the requirements of the dependencies. When calling a target, Ant resolves these dependencies and processes the targets accordingly. If you have defined a target that has direct or indirect dependencies on other targets, it is sufficient to call it up and Ant then carries out all the necessary work steps in the correct order.
A target can be specified as a default target in the project. This is usually the target that takes the necessary steps from the raw state or an intermediate state of the software project in order to create an executable state.
A target consists of calling up tasks (German "tasks"). They are comparable to commands in programming languages.
Syntax and interfaces
Since the build file is an XML file, its meaning does not depend on tab characters, spaces or path separators, which are defined differently on different operating systems . In particular, this is an improvement over the makefiles used by make .
Ant is an open system with defined interfaces. B. can be expanded as required by self-created tasks. Many Java tools support Ant. It can also be used in your own applications - e. B. Installation programs - integrate in order to take over a wide variety of mostly batch- like tasks.
Frequently used tasks
Ant contains over 150 tasks, whereby you can also program your own tasks in Java. This list contains some built-in tasks from Ant.
- javac for compiling source code.
- copy for copying files .
- delete to delete files or directories .
- mkdir for creating directories .
- junit for automated ( JUnit ) tests.
- move to rename files or directories.
- exec to run system programs. Attention: When using this task, you often become dependent on an operating system!
- zip for zipping , i.e. for compressing files.
- cvs for performing CVS operations.
- mail for sending e-mails .
- replace to replace text in files.
The pre-defined task Xslt for transforming an XML file into e.g. B. an HTML file using a given XSLT file.
Examples of targets
While tasks are implemented as Java classes, targets are defined in XML and call tasks. You can also create your own tasks in the form of Java classes.
The following excerpt from a typical build file shows two targets: build creates a directory and compiles a number of Java classes into it. It depends on another target clean that deletes some directories and files beforehand in order to clean up leftovers from previous calls.
<?xml version="1.0"?>
<project name="Demo" basedir="." default="build">
<property name="build.classes" value="bin" />
<property name="build.lib" value="lib" />
<property name="java.dir" value="." />
<property name="name" value="Wikipedia-Demo" />
<property name="manifest" value="manifest" />
<path id="classpath">
<pathelement location="." />
</path>
<!-- Anwendung bauen -->
<target name="build" depends="clean" description="Baut die komplette Anwendung">
<!-- Verzeichis anlegen -->
<mkdir dir="${build.classes}"/>
<!-- Quelltext kompilieren -->
<javac srcdir="${java.dir}"
destdir="${build.classes}"
debug="false"
deprecation="true"
optimize="true" >
<classpath refid="classpath" />
</javac>
<!-- Kopiert notwendige Dateien -->
<copy todir="${build.classes}">
<fileset dir="${java.dir}">
<include name="**/*.properties" />
<include name="**/*.gif" />
</fileset>
</copy>
<!-- Baut die JAR-Datei -->
<jar jarfile="${build.lib}/${name}.jar" manifest="${manifest}">
<fileset dir="${build.classes}"/>
</jar>
</target>
<!-- Aufräumen -->
<target name="clean" description="Räumt die temporär angelegten Dateien weg">
<!-- Löscht Dateien -->
<delete dir="${build.dir}" />
<delete dir="${dist.base}" />
<delete dir="${defaultdist.dir}" />
<delete>
<fileset dir="." includes="**/*~" defaultexcludes="no"/>
</delete>
</target>
</project>
The areas marked with a dollar sign ($) represent properties . These are variables previously defined in the project or in other targets .
See also
- Apache Maven - competing build management tool for Java
- Apache Ivy - Subproject of Apache Ant for the administration and integration of dependencies
- Gradle - another build management tool for Java
literature
- Bernd Matzke: Ant . Addison-Wesley, ISBN 3-8273-2066-6
- Erik Hatcher, Steve Loughran: Java Development with Ant . Mitp-Verlag, ISBN 3-8266-1409-7
- Stefan Edlich: Ant short & good . O'Reilly, ISBN 3-89721-241-2
- Jessy Tilly, Eric M. Burke: Ant, The Definitive Guide . O'Reilly, ISBN 0-596-00184-3
- Steve Loughran, Eric Hatcher: Ant in Action, Second Edition of Java Development with Ant . Manning, ISBN 1-932394-80-X
- Gunther Popp: Project automation with Ant . In: Configuration Management . dpunkt-Verlag, ISBN 978-3-89864-487-7
Web links
Individual evidence
- ↑ ant.apache.org .
- ^ The ant Open Source Project on Open Hub: Languages Page . In: Open Hub . (accessed on September 21, 2018).
- ↑ projects.apache.org . In: Open Hub . (accessed on April 8, 2020).