2019-08-14 admin


什么是ant,Apache Ant Adapter, execute Ant tasks from node



Experimental Apache Ant adapter for node.js.

This is a proof-of-concept more than anything else. Still unsure if it will actually work on multiple environments and if it is really a good idea.


Many people been using node.js to run build scripts and everyone is writting the same tasks for the most basic stuff like copying/concateneting/deleting/ziping files and it will take a long time before someone implements all the tasks present on Ant.

Projects like grunt, gear, jake, rivet, roto and many others are all writting their own tasks to do the same things. TBH I think a better approach would be to create separate libs that could do each task (or a group of tasks) and that wasn’t tied to a specific build tool, and create tools that abused this (no need to convert 3rd party lib into a plugin or author a new module just to use the methods inside your build files).

Ant contains many advanced tasks and is battle tested so it makes sense to reuse them instead of reinventing the wheel.

Ant is also not that easy to install on Windows since you need to configure the ANT_HOME, CLASSPATH and JAVA_HOME paths. So it’s easier to use a standalone version of Ant that is distributed together with the npm package. The Java Runtime is avaialble on most computers so calling the ant executable should work out of the box on most cases.

The idea is not to write multiple ant <target>s, but to treat Ant as a standalone lib that can be called from a node.js script. Performance isn’t that great (since JVM isn’t as fast as node) but it is still better than writting error-prone tasks that gets half of the job done.

Build tools based solely on configuration are doomed to “fail” the same way as Ant did “failed”. You can’t express all edge-cases with configuration without creating an overly complex system. Some things that could be easily done with a for loop and a few if/else are a huge PITA with a descriptive syntax (XML/JSON). The main reason why I moved my build scripts to node.js is to the get freedom to write new tasks by myself without major pains, locking down your build to a system that can only be extended by writting plugins that accepts a simple config object won’t scale up. Let’s use Ant for what it is good for (broad amount of battle tested tasks with flexible config options) and use plain JavaScript for those tasks that aren’t covered by Ant.

Maybe this project will motivate someone to port the most important Ant tasks to plain JavaScript. I still haven’t found a single node task that is as complete the ones provided by Ant, see for instance all the options available on the copy task (multiple include/exclude, filter, globmapper, download internet files, flatten, etc…).


The idea is to use the Ant as if it was a standalone library that can be called from node.js, that way you can reuse them in your custom node.js build files when necessary.

It will simply convert JSON-like objects into a temporary XML file and execute the standalone version of Ant passing the custom arguments. This tool is just a “bridge” between Node.js and the Ant JAR file.


Execute the test file to see a very basic example:

node test

You can run it from another node.js program:

var ant = require('ant');

    // concat task (
    concat : {
        fileset : {
            '@dir' : '.',
            include : {
                '@name' : '*.js'
}, function(err, stdout, stderror){
    // it doesn't throw any errors and also doesn't log the stdout by
    // default that way you can control what you want to do.
    if (stdout) console.log(stdout);
    if (stderror) console.log(stderror);
    if (err) throw err;


Right now it contains a single method exec() that accepts an object with each task and a callback. The tasks are just JSON-like representation of the XML markup needed to execute each task, node-ant will convert it back to XML during the exec.

ant.exec(tasks, [args], callback)

  • tasks:
    • JSON-like object containing Ant tasks to be executed.
  • [args]:
    • Command line arguments passed to the ant executable.
  • callback
    • Function executed after exec finishes. Will receive the following arguments: (err, stdout, stderr).

JXON syntax

Attributes starts with @.

> { foo : { '@bar' : 123 }}
<foo bar="123" />

The XML node text value is stored as the actual key value if node doesn’t contain attributes and/or child nodes or on a special property keyValue.

> {
    foo : 'Lorem Ipsum'
<foo>Lorem Ipsum</foo>

> {
    foo : {
        '@bar' : 123,
        keyValue : 'Lorem Ipsum'
<foo bar="123">Lorem Ipsum</foo>

> {
    concat : {
        fileset : {
            '@dir' : '.',
            include : {
                '@name' : '*.js'
<concat><fileset dir="."><include name="*.js" /></fileset></concat>

Use the Ant tasks documentation as reference.


This project is on early experimental phase. The way that ant.exec is called might change in the future, specially since the JXON format currently used doesn’t allow XML nodes with same name that aren’t adjacent to each other (object can’t have multiple properties with the same key). So I might end up changing the format to something closer to JSONML or use some sort of special token to differentiate duplicates (eg. echo#1, echo#2).


  • Test on a computer that doesn’t have JDK installed.
  • Check if it is possible to ship with a standalone version of JDK for the advanced tasks.
  • Make it possible to log to console without waiting the whole task to finish.


  • node.js 0.8.0+
  • Java
  • JDK 1.4+ (depending on which task you use)


v0.2.0 (2012/08/03)

  • add support to functions on tasks (for script task). Thanks to @Diullei
  • small refactor to jxon to improve readability and autoclose empty tags.

v0.1.0 (2012/08/02)

  • initial release.


node-ant is distributed under the MIT license.

Apache Ant is distributed under the Apache License.


转载请注明:文章转载自 JavaScript中文网 []



ant design pro 新增页面
ps:参考资料 1.ant design pro 1.在 src/routes/ 下面的任意一个文件夹下面创建一个页面 &#x2F;&#x2F; 填写如下内容 &#x2F;** NewPage.js内容 *&#x2F; import ...
&lt;button type=“button” id=“mainLike” data-id=“1190000014897318” class=&quot;btn btn-success btn-lg mr15 &quot;&gt;赞  |...
说明 React官方脚手架工具Create-react-app 用于快速创建React应用,但依旧有局限性,我们根据项目需求需要对Create-react-app的配置进行修改。这里针对引入Antd的两种配置方式进行配置。 方案 一. Re...
利用 ant-design-vue 实现一个支持多选的级联选择器
Preface I need to make a cascader which can support multiple choices. However, I didn’t find any ui which supports that ...
从零开始React + Dva + ant.design开发项目—路由
前言 之前发现了蚂蚁金服的,感觉这个框架有完整的设计交互规范,组件库丰富,交互友好,代码质量高,稳定性好,然后就一直想要在项目中使用下这个框架,但是之前一直都是用VUE的不怎么会React。今天学习了下怎么去使用Reac...
先说一下效果要求,上面一个下拉框,下面一个,要求上面选中的时候,下面的内容要跟着变。 因为想到react是数据驱动的,就不打算再用jq的那种隐藏显示了,而是通过在执行类型下拉框的onChange事件中,去改变下面的下拉框的数据,渲染出不...
Vant 一套基于Vue的移动端UI框架,有赞出品。 因为UI设计的够漂亮,源码结构也比较清晰,插件定位也比较明确,重要是实战过程中的使用体验不错。在最近的项目当中就使用 Vant 作为移动端的基础UI框架,但在实践过程中发现该框架和其他框...
React ant design表格导出数据为EXCEL表格数据
一、由于公司项目需要,需要将表格数据导出为EXCEL表格数据。环境React+Ant Design 二、安装插件js-export-excel yarn安装-记得以管理员身份执行 yarn add js-export-excel npm安...
AngularJS constant和value区别详解
angularJS可以通过constant(name,value)和value(name,value)对于创建服务也是很重要的。 相同点是:都可以接受两个参数,name和value。 区别: 1.constant(name,value)可以...
前几天看到有赞的vant,顿时对做一个商城项目产生了兴趣。说干就干,让我们来一步步实现。 预览地址:… 已实现购物车逻辑,商城首页等功能。 商城首页: 使用vuex搭建的购物车,将...