• Ant:Ant 入门


    背景

    自从有了 Maven 以后,Ant 视乎就不流行了,不过 Ant 还是有其应用场景的,Ant 的思想比较简洁,如下:

    1. 一个 project 包含多个 target(类似成员方法)。
    2. 一个 target 包含多个 task(类似语句)。
    3. project 中可以声明 property(类似成员变量)。
    4. project 中可以声明 path (特殊的成员变量)。
    5. target 可以声明其 depends。

    示例

    build.xml

     1 <?xml version="1.0" encoding="utf-8"?>
     2 <project name="02-ant" basedir="." default="help">
     3     <property name="src" value="src" />
     4     <property name="classes" value="bin" />
     5     <property name="output" value="output" />
     6 
     7     <path id="classpath">
     8         <pathelement path="${classes}" />
     9     </path>
    10 
    11     <target name="help" description="帮助">
    12         <echo>help - 帮助</echo>
    13         <echo>compile - 编译</echo>
    14         <echo>run - 运行</echo>
    15         <echo>build - 打包</echo>
    16         <echo>clean - 清理</echo>
    17     </target>
    18 
    19     <target name="compile" description="编译">
    20         <delete dir="${classes}" />
    21         <mkdir dir="${classes}" />
    22         <javac srcdir="${src}" destdir="${classes}" debug="true" includeantruntime="false">
    23             <classpath refid="classpath" />
    24         </javac>
    25     </target>
    26 
    27     <target name="run" description="运行" depends="compile">
    28         <java classname="Program" fork="yes">
    29             <classpath refid="classpath" />
    30             <arg line="段光伟" />
    31         </java>
    32     </target>
    33 
    34     <target name="build" description="打包" depends="compile">
    35         <delete dir="${output}" />
    36         <mkdir dir="${output}" />
    37         <jar destfile="${output}/app.jar" basedir="${classes}" includes="**/*.class">
    38             <manifest>
    39                 <attribute name="Main-Class" value="Program"/>
    40                 <attribute name="Class-Path" value="${classes}"/>
    41                 <attribute name="classpath" value="${classes}"/>
    42             </manifest>
    43         </jar>
    44     </target>
    45     
    46     <target name="clean" description="清理">
    47         <delete dir="${classes}" />
    48         <delete dir="${output}" />
    49     </target>
    50 
    51 </project>

    目录结构

    运行结果

    备注

    很多非 Java 环境都使用了 Ant,如:ExtJs 提供的工具。

  • 相关阅读:
    FreeSql学习笔记——11.LinqToSql
    前端实现阿里云oss直传 进度条
    Mysql授权用户 库名带横线的方法
    Clickhouse 单机版
    Linux OOM Killer
    git clone 失败 443 解决方法
    sentinel 基本原理
    sentinel 简介
    sentinel 中rule的加载过程
    vuex 重置清空所有数据(注意这里使用的Vuex4.x,3.x不可以这样实现重置数据)
  • 原文地址:https://www.cnblogs.com/happyframework/p/3388620.html
Copyright © 2020-2023  润新知