Apache Ant is a Java library and command-line tool whose mission is to drive processes described in build files as targets and extension points dependent upon each other. The main known usage of Ant is the build of Java applications. Ant supplies a number of built-in tasks allowing to compile, assemble, test and run Java applications. Ant can also be used effectively to build non Java applications, for instance C or C++ applications. More generally, Ant can be used to pilot any type of process which can be described in terms of targets and tasks.

Ant 主要用于构建 Java 应用程序。Ant 提供了许多内置任务,允许编译、组装、测试和运行 Java 应用程序。 Ant 主要有以下优点:

  1. 跨平台。Ant是纯Java语言编写的,所以具有很好的跨平台性。
  2. 操作简单。Ant由一个内置任务和可选任务组成,运行时需要一个XML文件(构建文件)。
  3. 易维护集成。构建文件是XML格式的文件,结构清晰易于维护,由于跨平台和操作简单,很容易集成到开发环境中。

Dockerfile

预先下载 Oracle “jdk-6u45-linux-x64.bin”到当前目录。

百度网盘: oracle_jdk6u45_linux64
链接: https://pan.baidu.com/s/1xm-DfStXGQxRmObZ26XxkQ
提取码:


[为隐藏内容,请登录(login)以显示!]

[root@ec-a ant1.9-jdk1.6]# tree
.
├── dockerfile
├── jdk-6u45-linux-x64.bin
# Dockerfile
#
FROM centos:7
LABEL maintainer="d0o0bz@qq.com" \
    provider="e.c."

ENV LANG="en_US.UTF-8" \
    LANGUAGE="en_US:en" \
    LC_ALL="en_US.UTF-8"

ENV JAVA_VERSION="1.6.0_45"
ENV JAVA_HOME="/usr/local/jdk${JAVA_VERSION}"
ENV PATH="${PATH}:${JAVA_HOME}/bin"

COPY ./jdk-6u45-linux-x64.bin /usr/local/

# 
RUN \cp -f /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
    # && yum update -y \
    && yum install -y wget vi \
    && echo "alias ll='ls -al'" >> /root/.bashrc

# ADD resources/jdk*.bin /usr/local/
WORKDIR /usr/local/
RUN chmod +x jdk-6u45-linux-x64.bin \
    && ./jdk-6u45-linux-x64.bin \
    && java -version \
    && javac -version \
    && rm -rf jdk-6u45-linux-x64.bin

#
# ANT
ENV ANT_VERSION=1.9.11
ENV ANT_HOME=/opt/ant

# change to tmp folder
WORKDIR /tmp

# Download and extract apache ant to opt folder
RUN wget --no-check-certificate --no-cookies http://archive.apache.org/dist/ant/binaries/apache-ant-${ANT_VERSION}-bin.tar.gz \
    && wget --no-check-certificate --no-cookies http://archive.apache.org/dist/ant/binaries/apache-ant-${ANT_VERSION}-bin.tar.gz.sha512 \
    && echo "$(cat apache-ant-${ANT_VERSION}-bin.tar.gz.sha512) apache-ant-${ANT_VERSION}-bin.tar.gz" | sha512sum -c \
    && tar -zvxf apache-ant-${ANT_VERSION}-bin.tar.gz -C /opt/ \
    && ln -s /opt/apache-ant-${ANT_VERSION} /opt/ant \
    && rm -f apache-ant-${ANT_VERSION}-bin.tar.gz \
    && rm -f apache-ant-${ANT_VERSION}-bin.tar.gz.sha512

# add executables to path
RUN update-alternatives --install "/usr/bin/ant" "ant" "/opt/ant/bin/ant" 1 && \
    update-alternatives --set "ant" "/opt/ant/bin/ant" \
    && ant -version

# change to root folder
WORKDIR /root




Building

[root@ec-a ant1.9-jdk1.6]# docker build -t ec/ant:1.9.11-jdk6u45 .

Sending build context to Docker daemon   72.1MB
Step 1/16 : FROM centos:7
 ---> 9f38484d220f

......

Step 15/16 : RUN update-alternatives --install "/usr/bin/ant" "ant" "/opt/ant/bin/ant" 1 &&     update-alternatives --set "ant" "/opt/ant/bin/ant"     && ant -version
 ---> Running in ecbc4ba6f44a
Apache Ant(TM) version 1.9.11 compiled on March 23 2018
Removing intermediate container ecbc4ba6f44a
 ---> ff11da2188b9
Step 16/16 : WORKDIR /root
 ---> Running in d37fdb50c710
Removing intermediate container d37fdb50c710
 ---> 1019d00632da
Successfully built 1019d00632da
Successfully tagged ec/ant:1.9.11-jdk6u45

参考资料:
http://ant.apache.org/
https://github.com/frekele/docker-ant