-
Notifications
You must be signed in to change notification settings - Fork 16
/
index.html
1566 lines (1549 loc) · 284 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en" class="no-js">
<head>
<meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ant与前端</title>
<link rel="stylesheet" type="text/css" href="./assets/bootstrap.min.css"/>
<link rel="stylesheet" type="text/css" href="./assets/bootstrap-responsive.css"/>
<link rel="stylesheet" type="text/css" href="./assets/facebox.css"/>
<link rel="stylesheet" type="text/css" href="assets/doc.css"/>
<script src="assets/modernizr.custom.79639.js"></script>
</head>
<body>
<div id="container" class="container">
<div class="menu-panel">
<h3>教程目录</h3>
<ul id="menu-toc" class="menu-toc J_Menu">
<li class="menu-toc-current"><a href="#index">ant简介</a></li>
<li><a href="#install">ant的安装和简单使用</a></li>
<li><a href="#build-xml">ant的构建文件入门</a></li>
<li><a href="#targets">基础任务标签的使用</a></li>
<li><a href="#property">property属性标签的使用</a></li>
<li><a href="#dataType">dataType的用法</a></li>
<li><a href="#yui-compressor">ant结合jsdoc构建js文档</a></li>
<li><a href="#jsdoc">利用jsdoc提高自动提示</a></li>
<li><a href="#pro-build">JsTestDriver的使用</a></li>
</ul>
</div>
<div class="bb-custom-wrapper">
<div id="bb-bookblock" class="bb-bookblock">
<div class="bb-item" id="index">
<div class="content J_Content">
<div class="scroller">
<div class="row">
<div class="span4">
<img src="http://s1.36ria.com/201302/4922/32596_o.png"
width="350" height="450"/>
</div>
<div class="span7">
<h2>ant简介</h2>
<ul>
<li>用途:非常强大的构建工具</li>
<li>版本:1.8.4</li>
<li>下载:<a href="http://labs.renren.com/apache-mirror//ant/binaries/apache-ant-1.8.4-bin.zip" class="broken_link">1.8.4-bin.zip</a></li>
<li>ant使用文档:<a href="http://ant.apache.org/manual/index.html">http://ant.apache.org/manual/index.html</a></li>
</ul>
<p>ant作为目前中国最受欢迎的开源构建工具,广泛应用于java工程构建。也许你会感到很疑惑,js作为动态语言,并不需要编译过程,为什么需要ant这样的构建工具呢?ant能够帮助前端工程师解决那些问题呢?</p>
<h3>为什么前端工程师需要ant?</h3>
<p>来看个经典的应用场景:<br />
在你的页面中需要引用不少的jquery插件,比如plug-1.js、plug-2.js、plug-3.js,yslow关于前端性能优化的第一建议就是页面应该保持尽量少的js和css引用。明显这个场景违背了这个建议,所以我们需要合并这些js插件,合并成plug-combine.js文件,传统的做法是人肉合并,以前明河也是这么干的,但遇到了如下烦恼,plug-1.js是自己写的插件,经常要更新这个文件的代码,每次更新完都要重新人肉更新下plug-combine.js,作为一个懒人,明河在想,“有没有一个工具可以帮我自动合并文件呢?当然合并后能够自动调用压缩工具压缩文件就更棒了!”。ant这个神奇的工具就是用来帮前端偷这样的懒的!</p>
<h3>ant能帮前端干些什么呢?</h3>
<ul>
<li>合并js/css文件;</li>
<li>调用YUI Compressor自动压缩css文件,调用Google Closure Compiler自动压缩js;</li>
<li>快速批量复制/删除指定文件;</li>
<li>调用jsDoc工具,自动生成js文档;</li>
<li>连接FTP,将代码快速发布到指定服务器;</li>
<li>将文件自动上传到svn上;</li>
<li>自动打包成zip文件</li>
<li>...</li>
</ul>
<p>ant强大得超乎你的想象,ant提供了一整套的任务列表帮你从重复耗时的构建流程中解脱出来!看到ant这只神奇的蚂蚁能做如此多的事,心动了吗?那么跟着明河来学学如何使用ant。<br />
明河要强调的一点是<strong>ant很简单</strong>,只要你有足够的耐心,1天内就可基本掌握其使用方法。
</p>
</div>
</div>
</div>
</div>
</div>
<div class="bb-item" id="install">
<div class="content J_Content">
<div class="scroller">
<h2>Ant的安装和简单使用</h2>
<h3>1.下载<a href="http://labs.renren.com/apache-mirror//ant/binaries/apache-ant-1.8.2-bin.zip" class="broken_link">ant</a></h3>
<p>你下载下来的ant,应该包含如下文件:<br />
<a href="http://www.36ria.com/4411/ant-files" rel="attachment wp-att-4412"><img src="http://www.36ria.com/wp-content/uploads/2011/08/ant-files.png" alt="" title="ant-files" width="430" height="387" class="alignnone size-full wp-image-4412" /></a></p>
<h3>2.安装java运行环境</h3>
<p>ant是java程序,所以依赖于java运行环境,如果你的机子已经安装JDK,那么请跳过这一步,如果没有请先下载JDK,<a href="http://www.oracle.com/technetwork/java/javase/downloads/index.html">传送门在此</a>。<br />
(PS:请运行“CMD”,然后键入“javac”,如果出现如下界面说明java环境OK。)<br />
<a href="http://www.36ria.com/4411/javac" rel="attachment wp-att-4414"><img src="http://www.36ria.com/wp-content/uploads/2011/08/javac.png" alt="" title="javac" width="422" height="230" class="alignnone size-full wp-image-4414" /></a><br />
如果出现“’javac’ 不是内部或外部命令,也不是可运行的程序或批处理文件。”,那么请设置下java环境变量。<br />
设置方法参见,明河之前写的<a href="http://www.36ria.com/3948">《YUI Compressor快速使用指南—web前端开发七武器》</a>,这里不再累述。</p>
<h3>3.配置环境变量</h3>
<p>右击“计算机”,点击“系统设置”,出现如下界面:<br />
<a href="http://www.36ria.com/4411/environment" rel="attachment wp-att-4413"><img src="http://www.36ria.com/wp-content/uploads/2011/08/environment.png" alt="" title="environment" width="600" height="545" class="alignnone size-full wp-image-4413" /></a><br />
新建系统变量,变量名:<strong>ANT_HOME</strong>,变量值:d:\soft\ant,变量值指向你本机ant的解压目录,请勿直接copy这个变量值。<br />
<a href="http://www.36ria.com/4411/ant%e2%80%94%e2%80%94home" rel="attachment wp-att-4415"><img src="http://www.36ria.com/wp-content/uploads/2011/08/ant——home.png" alt="" title="ant——home" width="362" height="140" class="alignnone size-full wp-image-4415" /></a><br />
修改变量:<strong>path</strong>,在最后添加:%ANT_HOME%\bin;<br />
<a href="http://www.36ria.com/4411/ant-2" rel="attachment wp-att-4416"><img src="http://www.36ria.com/wp-content/uploads/2011/08/ant.png" alt="" title="ant" width="365" height="150" class="alignnone size-full wp-image-4416" /></a></p>
<h3>4.试运行ant</h3>
<p>在”CMD”界面,输入“ant”,如果出现以下内容,说明配置成功!<br />
<a href="http://www.36ria.com/4411/ant-2-2" rel="attachment wp-att-4417"><img src="http://www.36ria.com/wp-content/uploads/2011/08/ant-2.png" alt="" title="ant-2" width="334" height="86" class="alignnone size-full wp-image-4417" /></a></p>
<h2>ant版的hello world!</h2>
<p>在d盘新建个<strong>ant-demo</strong>的目录。<br />
在该目录下新建个build.xml,代码如下:</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: Olive;"><?</span><span style="color: Green;">xml</span><span style="color: Gray;"> </span><span style="color: #00008b;">version</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">1.0</span><span style="color: #8b0000;">"</span><span style="color: Olive;">?></span></li>
<li><span style="color: Olive;"><</span><span style="color: Green;">project</span><span style="color: Gray;"> </span><span style="color: #00008b;">name</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">refund</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: #00008b;">default</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">build</span><span style="color: #8b0000;">"</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">target</span><span style="color: Gray;"> </span><span style="color: #00008b;">name</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">build</span><span style="color: #8b0000;">"</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">echo</span><span style="color: Olive;">></span><span style="color: Gray;">Hello world!</span><span style="color: Olive;"></</span><span style="color: Green;">echo</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">concat</span><span style="color: Gray;"> </span><span style="color: #00008b;">destfile</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">a_b.js</span><span style="color: #8b0000;">"</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">path</span><span style="color: Gray;"> </span><span style="color: #00008b;">path</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">a.js</span><span style="color: #8b0000;">"</span><span style="color: Olive;">/></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">path</span><span style="color: Gray;"> </span><span style="color: #00008b;">path</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">b.js</span><span style="color: #8b0000;">"</span><span style="color: Olive;">/></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"></</span><span style="color: Green;">concat</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"></</span><span style="color: Green;">target</span><span style="color: Olive;">></span></li>
<li><span style="color: Olive;"></</span><span style="color: Green;">project</span><span style="color: Olive;">></span></li></ol></div>
<p>再准备二个用于合并的js文件,比如a.js和b.js,(随便在二个文件中加些js代码)。<br />
进入cmd界面,敲入ant,留意必须先将目录指向build.xml的根目录。<br />
<a href="http://www.36ria.com/4411/ant-hello" rel="attachment wp-att-4423"><img src="http://www.36ria.com/wp-content/uploads/2011/08/ant-hello.png" alt="" title="ant-hello" width="514" height="329" class="alignnone size-full wp-image-4423" /></a><br />
你将成功输出a_b.js文件,目录结构如下;<br />
<a href="http://www.36ria.com/4411/ant-files-2" rel="attachment wp-att-4419"><img src="http://www.36ria.com/wp-content/uploads/2011/08/ant-files-2.png" alt="" title="ant-files-2" width="219" height="145" class="alignnone size-full wp-image-4419" /></a><br />
build.xml中的代码是什么意思呢?请看下文分解</p>
</div>
</div>
</div>
<div class="bb-item" id="build-xml">
<div class="content J_Content">
<div class="scroller">
<h2>构建文件入门</h2>
<h3>1.什么是构建文件?</h3>
<p>构建文件是ant执行工程构建的入门文件,构建的所有任务都必须只能写在构建文件内,构建文件必须是符合标准的xml文件,默认的构建文件为build.xml,当你键入“ant”命名执行时,默认执行<strong>build.xml</strong>。</p>
<h4>标准构建文件模板:</h4>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: Olive;"><?</span><span style="color: Green;">xml</span><span style="color: Gray;"> </span><span style="color: #00008b;">version</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">1.0</span><span style="color: #8b0000;">"</span><span style="color: Olive;">?></span></li>
<li><span style="color: Olive;"><</span><span style="color: Green;">project</span><span style="color: Gray;"> </span><span style="color: #00008b;">name</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">refund</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: #00008b;">default</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">build</span><span style="color: #8b0000;">"</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">target</span><span style="color: Gray;"> </span><span style="color: #00008b;">name</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">build</span><span style="color: #8b0000;">"</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"></</span><span style="color: Green;">target</span><span style="color: Olive;">></span></li>
<li><span style="color: Olive;"></</span><span style="color: Green;">project</span><span style="color: Olive;">></span></li></ol></div>
<h4>关键点说明</h4>
<ul>
<li>第一行为xml声明,必须存在;</li>
<li>有且仅有一个<strong>project</strong>根标签;</li>
<li>default属性执行默认目标;</li>
<li>target(任务目标);</li>
<li>task:任务,是构建文件的最小执行单位,是具体干活的标签;</li>
<li>property:特性,或理解为属性。</li>
</ul>
<h3>2.新的demo代码</h3>
<p>改变下上一篇的demo,增加点复杂点:创建一个src目录,将合并后的文件放在src目录下,并在合并后的文件内顶部添加一行自定义的合并注释。<br />
新的demo中的build.xml:</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: Olive;"><?</span><span style="color: Green;">xml</span><span style="color: Gray;"> </span><span style="color: #00008b;">version</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">1.0</span><span style="color: #8b0000;">"</span><span style="color: Olive;">?></span></li>
<li><span style="color: Olive;"><</span><span style="color: Green;">project</span><span style="color: Gray;"> </span><span style="color: #00008b;">name</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">refund</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: #00008b;">default</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">build</span><span style="color: #8b0000;">"</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">property</span><span style="color: Gray;"> </span><span style="color: #00008b;">name</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">concat.note</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: #00008b;">value</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">//合并自a.js和b.js</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: Olive;">/></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">target</span><span style="color: Gray;"> </span><span style="color: #00008b;">name</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">build</span><span style="color: #8b0000;">"</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">echo</span><span style="color: Olive;">></span><span style="color: Gray;">生成src目录</span><span style="color: Olive;"></</span><span style="color: Green;">echo</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">mkdir</span><span style="color: Gray;"> </span><span style="color: #00008b;">dir</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">src</span><span style="color: #8b0000;">"</span><span style="color: Olive;">/></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">echo</span><span style="color: Olive;">></span><span style="color: Gray;">开始合并文件</span><span style="color: Olive;"></</span><span style="color: Green;">echo</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">concat</span><span style="color: Gray;"> </span><span style="color: #00008b;">destfile</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">src/a_b.js</span><span style="color: #8b0000;">"</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">header</span><span style="color: Gray;"> </span><span style="color: #00008b;">trimleading</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">yes</span><span style="color: #8b0000;">"</span><span style="color: Olive;">></span><span style="color: Gray;">${concat.note}</span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"></</span><span style="color: Green;">header</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">path</span><span style="color: Gray;"> </span><span style="color: #00008b;">path</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">a.js</span><span style="color: #8b0000;">"</span><span style="color: Olive;">/></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">path</span><span style="color: Gray;"> </span><span style="color: #00008b;">path</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">b.js</span><span style="color: #8b0000;">"</span><span style="color: Olive;">/></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"></</span><span style="color: Green;">concat</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"></</span><span style="color: Green;">target</span><span style="color: Olive;">></span></li>
<li><span style="color: Olive;"></</span><span style="color: Green;">project</span><span style="color: Olive;">></span></li></ol></div>
<p>在“CMD”界面运行“ant”命令,结果如下:(请确保你的demo中有a.js和b.js)<br />
<a href="http://www.36ria.com/4436/2011-8-26-10-53-06" rel="attachment wp-att-4437"><img src="http://www.36ria.com/wp-content/uploads/2011/08/2011-8-26-10-53-06.png" alt="" title="2011-8-26 10-53-06" width="317" height="167" class="alignnone size-full wp-image-4437" /></a><br />
成功运行后你就会发现生成了一个src目录,目录下有个a_b.js文件,文件的第一行注释是//合并自a.js和b.js,完全符合我们构建要求!<br />
这个demo的代码会比上一篇教程复杂了不少,明河来逐个说明下。</p>
<h4>property标签</h4>
<p><strong>property</strong>标签为特性标签,你可以理解为编程语言中的属性或者变量,它起到的作用和变量是类似的,赋值后的property,可以在之后的目标任务内方便的引用。<br />
property有二种数据元素:</p>
<ul>
<li>以名—值对出现的简单数据定义形式,比如demo中的
<property name="concat.note" value="//合并自a.js和b.js" />;</li>
<li><strong>dataType</strong>复杂数据元素,比如fileset,日后会讲解到。</li>
</ul>
<p><strong>如何引用property呢?</strong><br />
非常简单,在你需要引用的地方使用<strong>${property名}</strong>即可,比如demo中的${concat.note}。<br />
<strong>property的location属性</strong><br />
property除了value属性外,还有个<strong>location</strong>属性,起到的作用类似,区别是location属性用来保存路径,location带了路径转换功能,会将路径转成绝对路径,如果你的路径是/,它会自动转换成\,这个属性日后会经常用到。比如下面的代码:</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: Olive;"><</span><span style="color: Green;">property</span><span style="color: Gray;"> </span><span style="color: #00008b;">name</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">refund.dir</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: #00008b;">location</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">d:/ant-demo/</span><span style="color: #8b0000;">"</span><span style="color: Olive;">/></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">property</span><span style="color: Gray;"> </span><span style="color: #00008b;">name</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">refund.dir2</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: #00008b;">location</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">../</span><span style="color: #8b0000;">"</span><span style="color: Olive;">/></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">target</span><span style="color: Gray;"> </span><span style="color: #00008b;">name</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">build</span><span style="color: #8b0000;">"</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">echo</span><span style="color: Olive;">></span><span style="color: Gray;">${refund.dir}</span><span style="color: Olive;"></</span><span style="color: Green;">echo</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">echo</span><span style="color: Olive;">></span><span style="color: Gray;">${refund.dir2}</span><span style="color: Olive;"></</span><span style="color: Green;">echo</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"></</span><span style="color: Green;">target</span><span style="color: Olive;">></span></li></ol></div>
<p>看看输出结果,留意明河取的是代码片段,请根据实际情况做下修改。</p>
<h4>target标签</h4>
<p><strong>target</strong>标签非常的重要,“目标”标签可以理解为一系列任务标签的容器,是对任务的隐式说明,构建文件允许出现多个target,明河的建议是使用更细的target,比如demo中的代码可以修改为:</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: Olive;"><?</span><span style="color: Green;">xml</span><span style="color: Gray;"> </span><span style="color: #00008b;">version</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">1.0</span><span style="color: #8b0000;">"</span><span style="color: Olive;">?></span></li>
<li><span style="color: Olive;"><</span><span style="color: Green;">project</span><span style="color: Gray;"> </span><span style="color: #00008b;">name</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">refund</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: #00008b;">default</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">build</span><span style="color: #8b0000;">"</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">property</span><span style="color: Gray;"> </span><span style="color: #00008b;">name</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">concat.note</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: #00008b;">value</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">//合并自a.js和b.js</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: Olive;">/></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">target</span><span style="color: Gray;"> </span><span style="color: #00008b;">name</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">build</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: #00008b;">depends</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">mkdir,concat</span><span style="color: #8b0000;">"</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"></</span><span style="color: Green;">target</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">target</span><span style="color: Gray;"> </span><span style="color: #00008b;">name</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">mkdir</span><span style="color: #8b0000;">"</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">echo</span><span style="color: Olive;">></span><span style="color: Gray;">生成src目录</span><span style="color: Olive;"></</span><span style="color: Green;">echo</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">mkdir</span><span style="color: Gray;"> </span><span style="color: #00008b;">dir</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">src</span><span style="color: #8b0000;">"</span><span style="color: Olive;">/></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"></</span><span style="color: Green;">target</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">target</span><span style="color: Gray;"> </span><span style="color: #00008b;">name</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">concat</span><span style="color: #8b0000;">"</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">echo</span><span style="color: Olive;">></span><span style="color: Gray;">开始合并文件</span><span style="color: Olive;"></</span><span style="color: Green;">echo</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">concat</span><span style="color: Gray;"> </span><span style="color: #00008b;">destfile</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">src/a_b.js</span><span style="color: #8b0000;">"</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">header</span><span style="color: Gray;"> </span><span style="color: #00008b;">trimleading</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">yes</span><span style="color: #8b0000;">"</span><span style="color: Olive;">></span><span style="color: Gray;">${concat.note}</span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"></</span><span style="color: Green;">header</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">path</span><span style="color: Gray;"> </span><span style="color: #00008b;">path</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">a.js</span><span style="color: #8b0000;">"</span><span style="color: Olive;">/></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">path</span><span style="color: Gray;"> </span><span style="color: #00008b;">path</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">b.js</span><span style="color: #8b0000;">"</span><span style="color: Olive;">/></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"></</span><span style="color: Green;">concat</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"></</span><span style="color: Green;">target</span><span style="color: Olive;">></span></li>
<li><span style="color: Olive;"></</span><span style="color: Green;">project</span><span style="color: Olive;">></span></li></ol></div>
<p>这里明河将一个target拆成了多个target,留意属性depends。<br />
depends用于处理目标依赖,比如这里“build”依赖于“mkdir”和“concat”目标,那么ant会优先执行“mkdir”和“concat”然后才执行“build”。这种依赖机制是ant非常重要的处理模式!体现出ant的灵活性!</p>
<h4>task任务标签</h4>
<p>任务是ant构建文件的最小构建块,是构建的实施者,demo中的echo、<strong>concat</strong>都是任务标签,那么ant能完成多少个任务呢,或者说ant有多少构建功能呢?<a href="http://ant.apache.org/manual/index.html">请猛击这里查看</a>,(有个task list)。看了这个任务清单,我想你可以体会到ant究竟有多强大!<br />
明河不会对所有的任务标签进行讲解,只讲解前端常用的几个关键任务标签,下一篇教程将详细讲解concat、mkdir、copy等标签用法。</p>
</div>
</div>
</div>
<div class="bb-item" id="targets">
<div class="content J_Content">
<div class="scroller">
<h2>基础任务标签</h2>
<p>前面二篇教程,主要讲解了ant的基础概念以及二个简单的实际demo,今天这篇文章,明河带大家认识下前端常用的几个ant常用任务标签。</p>
<h3>1.concat:合并文件</h3>
<p>concat标签非常常用,我们前端使用ant的一个核心任务,就是合并js/css文件以减少http请求。</p>
<h4>1.1 concat的主要属性</h4>
<table border="0" cellspacing="0" cellpadding="0" class="tab1">
<colgroup>
<col width="160">
<col>
</colgroup>
<thead>
<tr>
<td valign="top">
<p><strong>属性</strong></p>
</td>
<td valign="top">
<p><strong>说明</strong></p>
</td>
</tr>
</thead>
<tbody>
<tr>
<td valign="top">
<p><strong>destfile</strong></p>
</td>
<td valign="top">
<p>合并后的文件的目标路径,包含文件名</p>
</td>
</tr>
<tr>
<td valign="top">
<p><strong>overwrite</strong></p>
</td>
<td valign="top">
<p>是否允许覆盖目标文件,默认是允许</p>
</td>
</tr>
<tr>
<td valign="top">
<p><strong>outputencoding</strong></p>
</td>
<td valign="top">
<p>输出的目标文件的编码</p>
</td>
</tr>
</tbody>
</table>
<p>全部属性请看ant的英文文档。</p>
<h4>1.2 header子标签</h4>
<p>第二篇教程的demo,concat标签内有个header标签,这个标签是用来修改输出的目标文件的头部内容,比如你可以在目标前添加一行合并信息注释等,比如下面的代码:</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: Olive;"><</span><span style="color: Green;">concat</span><span style="color: Gray;"> </span><span style="color: #00008b;">destfile</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">src/a_b.js</span><span style="color: #8b0000;">"</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">header</span><span style="color: Gray;"> </span><span style="color: #00008b;">trimleading</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">yes</span><span style="color: #8b0000;">"</span><span style="color: Olive;">></span><span style="color: Gray;">//合并自a.js和b.js</span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"></</span><span style="color: Green;">header</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">path</span><span style="color: Gray;"> </span><span style="color: #00008b;">path</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">a.js</span><span style="color: #8b0000;">"</span><span style="color: Olive;">/></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">path</span><span style="color: Gray;"> </span><span style="color: #00008b;">path</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">b.js</span><span style="color: #8b0000;">"</span><span style="color: Olive;">/></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"></</span><span style="color: Green;">concat</span><span style="color: Olive;">></span></li></ol></div>
<p>header有个trimleading用于清理行空白的属性比较关键,其他属性明河也不太理解,旧不翻译了,有兴趣的看英文文档。</p>
<h4>1.3 concat的一些demo</h4>
<p><strong>合并指定路径的文件:</strong></p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: Olive;"><</span><span style="color: Green;">concat</span><span style="color: Gray;"> </span><span style="color: #00008b;">destfile</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">src/a_b.js</span><span style="color: #8b0000;">"</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">path</span><span style="color: Gray;"> </span><span style="color: #00008b;">path</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">a.js</span><span style="color: #8b0000;">"</span><span style="color: Olive;">/></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">path</span><span style="color: Gray;"> </span><span style="color: #00008b;">path</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">b.js</span><span style="color: #8b0000;">"</span><span style="color: Olive;">/></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"></</span><span style="color: Green;">concat</span><span style="color: Olive;">></span></li></ol></div>
<p>(PS:path子标签的作用在于指定文件路径。)<br />
<strong>合并特定的文件集合:</strong></p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: Olive;"><</span><span style="color: Green;">concat</span><span style="color: Gray;"> </span><span style="color: #00008b;">destfile</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">test.js</span><span style="color: #8b0000;">"</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">fileset</span><span style="color: Gray;"> </span><span style="color: #00008b;">dir</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">src</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: #00008b;">includes</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">*.js</span><span style="color: #8b0000;">"</span><span style="color: Olive;">/></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"></</span><span style="color: Green;">concat</span><span style="color: Olive;">></span></li></ol></div>
<p>合并src目录下的所有文件,fileset这个标签非常重要,在讲解dataType时会重点说明。<br />
<strong>给目标文件增加文字:</strong><br />
利用header标签,demo已经贴出,不再重复贴出。</p>
<h3>2.mkdir:创建一个新的目录</h3>
<p>比较简单,只有一个属性<strong>dir</strong>,用来指定创建的目录路径,不只是名称哦。<br />
贴个demo:</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: Olive;"><</span><span style="color: Green;">mkdir</span><span style="color: Gray;"> </span><span style="color: #00008b;">dir</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">${dist}/lib</span><span style="color: #8b0000;">"</span><span style="color: Olive;">/></span></li></ol></div>
<p>在${dist}(属性引用)下创建一个名为lib的目录。</p>
<h3>3.copy:复制指定文件到指定位置</h3>
<h4>3.1.copy主要属性</h4>
<table border="0" cellspacing="0" cellpadding="0" class="tab1">
<colgroup>
<col width="160">
<col>
</colgroup>
<thead>
<tr>
<td valign="top">
<p><strong>属性</strong></p>
</td>
<td valign="top">
<p><strong>说明</strong></p>
</td>
</tr>
</thead>
<tbody>
<tr>
<td valign="top">
<p><strong>file</strong></p>
</td>
<td valign="top">
<p>必有属性,用于复制的源文件,除非存在fileset等dataType</p>
</td>
</tr>
<tr>
<td valign="top">
<p><strong>tofile</strong></p>
</td>
<td valign="top">
<p>将文件复制到该路径</p>
</td>
</tr>
<tr>
<td valign="top">
<p><strong>todir</strong></p>
</td>
<td valign="top">
<p>将文件复制到该目录</p>
</td>
</tr>
<tr>
<td valign="top">
<p><strong>outputencoding</strong></p>
</td>
<td valign="top">
<p>目标文件的编码</p>
</td>
</tr>
</tbody>
</table>
<h4>3.2.copy的demo</h4>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: Olive;"><</span><span style="color: Green;">copy</span><span style="color: Gray;"> </span><span style="color: #00008b;">file</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">a.js</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: #00008b;">tofile</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">src/a.js</span><span style="color: #8b0000;">"</span><span style="color: Olive;">/></span></li></ol></div>
<p>将a.js文件复制到src目录下,这里你可以修改文件名哦。</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: Olive;"><</span><span style="color: Green;">copy</span><span style="color: Gray;"> </span><span style="color: #00008b;">file</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">a</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: #00008b;">todir</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">src</span><span style="color: #8b0000;">"</span><span style="color: Olive;">/></span></li></ol></div>
<p>将a.js文件复制到src目录下。</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: Olive;"><</span><span style="color: Green;">copy</span><span style="color: Gray;"> </span><span style="color: #00008b;">todir</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">build</span><span style="color: #8b0000;">"</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">fileset</span><span style="color: Gray;"> </span><span style="color: #00008b;">dir</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">src</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: #00008b;">excludes</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">**/*.css</span><span style="color: #8b0000;">"</span><span style="color: Olive;">/></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"></</span><span style="color: Green;">copy</span><span style="color: Olive;">></span></li></ol></div>
<p>将src的文件(排除css文件)复制到build目录下。excludes=”**/*.css”的含义在讲解fileset会说明。</p>
<h3>4.delete:删除指定文件(目录)</h3>
<h4>4.1.delete的主要属性</h4>
<table border="0" cellspacing="0" cellpadding="0" class="tab1">
<colgroup>
<col width="160">
<col>
</colgroup>
<thead>
<tr>
<td valign="top">
<p><strong>属性</strong></p>
</td>
<td valign="top">
<p><strong>说明</strong></p>
</td>
</tr>
</thead>
<tbody>
<tr>
<td valign="top">
<p><strong>file</strong></p>
</td>
<td valign="top">
<p>删除的目标文件</p>
</td>
</tr>
<tr>
<td valign="top">
<p><strong>dir</strong></p>
</td>
<td valign="top">
<p>删除的目标目录</p>
</td>
</tr>
<tr>
<td valign="top">
<p><strong>verbose</strong></p>
</td>
<td valign="top">
<p>是否显示每个删除的目标文件名称</p>
</td>
</tr>
<tr>
<td valign="top">
<p><strong>quiet</strong></p>
</td>
<td valign="top">
<p>当设置为true,删除的文件或目录出现错误时不抛出任何异常,正常情况下会有删除失败说明</p>
</td>
</tr>
</tbody>
</table>
<h4>4.2.delete的demo</h4>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: Olive;"><</span><span style="color: Green;">delete</span><span style="color: Gray;"> </span><span style="color: #00008b;">file</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">/lib/ant.jar</span><span style="color: #8b0000;">"</span><span style="color: Olive;">/></span></li>
<li><span style="color: Olive;"><</span><span style="color: Green;">delete</span><span style="color: Gray;"> </span><span style="color: #00008b;">dir</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">lib</span><span style="color: #8b0000;">"</span><span style="color: Olive;">/></span></li></ol></div>
<p>删除ant.jar文件和lib目录。</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: Olive;"><</span><span style="color: Green;">delete</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">fileset</span><span style="color: Gray;"> </span><span style="color: #00008b;">dir</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">.</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: #00008b;">includes</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">**/*.bak</span><span style="color: #8b0000;">"</span><span style="color: Olive;">/></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"></</span><span style="color: Green;">delete</span><span style="color: Olive;">></span></li></ol></div>
<p>删除根目录下的所有后缀是.bak的文件。</p>
<h3>5.echo:向ant控制台打印消息</h3>
<p>echo在调试ant任务时非常有用,也可以在任务执行后打印一些任务完成提示消息等。<br />
实际上echo也可以把消息打印到指定文件,形成build日志,只需要指定file参数即可。</p>
<table border="0" cellspacing="0" cellpadding="0" class="tab1">
<colgroup>
<col width="160">
<col>
</colgroup>
<thead>
<tr>
<td valign="top">
<p><strong>属性</strong></p>
</td>
<td valign="top">
<p><strong>说明</strong></p>
</td>
</tr>
</thead>
<tbody>
<tr>
<td valign="top">
<p><strong>message</strong></p>
</td>
<td valign="top">
<p>想要打印的消息</p>
</td>
</tr>
<tr>
<td valign="top">
<p><strong>file</strong></p>
</td>
<td valign="top">
<p>消息打印到指定文件</p>
</td>
</tr>
<tr>
<td valign="top">
<p><strong>append</strong></p>
</td>
<td valign="top">
<p>将消息追加到已经存在的文件</p>
</td>
</tr>
<tr>
<td valign="top">
<p><strong>level</strong></p>
</td>
<td valign="top">
<p>指定消息的类型,有”error”, “warning”, “info”, “verbose”, “debug” </p>
</td>
</tr>
</tbody>
</table>
<p>来看典型的echo任务代码:</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: Olive;"><</span><span style="color: Green;">echo</span><span style="color: Gray;"> </span><span style="color: #00008b;">message</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">Hello, world</span><span style="color: #8b0000;">"</span><span style="color: Olive;">/></span></li>
<li><span style="color: Olive;"><</span><span style="color: Green;">echo</span><span style="color: Olive;">></span><span style="color: Gray;">Hello, world</span><span style="color: Olive;"></</span><span style="color: Green;">echo</span><span style="color: Olive;">></span></li>
<li><span style="color: Olive;"><</span><span style="color: Green;">dirname</span><span style="color: Gray;"> </span><span style="color: #00008b;">property</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">current.dir</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: #00008b;">file</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">./</span><span style="color: #8b0000;">"</span><span style="color: Olive;">/></span></li>
<li><span style="color: Olive;"><</span><span style="color: Green;">echo</span><span style="color: Olive;">></span><span style="color: Gray;">${current.dir}</span><span style="color: Olive;"></</span><span style="color: Green;">echo</span><span style="color: Olive;">></span></li></ol></div>
<p>echo打印property属性值,是个非常常用的调试技巧。<br />
上述代码中有个dirname,这个任务是用来做啥的呢?接下去看。</p>
<h3>6.dirname:获取文件的目录路径</h3>
<p>dirname只有二个参数:</p>
<table border="0" cellspacing="0" cellpadding="0" class="tab1">
<colgroup>
<col width="160">
<col>
</colgroup>
<thead>
<tr>
<td valign="top">
<p><strong>属性</strong></p>
</td>
<td valign="top">
<p><strong>说明</strong></p>
</td>
</tr>
</thead>
<tbody>
<tr>
<td valign="top">
<p><strong>file</strong></p>
</td>
<td valign="top">
<p>文件路径</p>
</td>
</tr>
<tr>
<td valign="top">
<p><strong>property</strong></p>
</td>
<td valign="top">
<p>指定属性名称</p>
</td>
</tr>
</tbody>
</table>
<p>来看下使用代码:</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: Olive;"><?</span><span style="color: Green;">xml</span><span style="color: Gray;"> </span><span style="color: #00008b;">version</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">1.0</span><span style="color: #8b0000;">"</span><span style="color: Olive;">?></span></li>
<li><span style="color: Olive;"><</span><span style="color: Green;">project</span><span style="color: Gray;"> </span><span style="color: #00008b;">name</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">test</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: #00008b;">default</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">build</span><span style="color: #8b0000;">"</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">target</span><span style="color: Gray;"> </span><span style="color: #00008b;">name</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">build</span><span style="color: #8b0000;">"</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">dirname</span><span style="color: Gray;"> </span><span style="color: #00008b;">property</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">antfile.dir</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: #00008b;">file</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">${ant.file}</span><span style="color: #8b0000;">"</span><span style="color: Olive;">/></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">property</span><span style="color: Gray;"> </span><span style="color: #00008b;">name</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">antfile2.dir</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: #00008b;">location</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">${ant.file}</span><span style="color: #8b0000;">"</span><span style="color: Olive;">/></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">echo</span><span style="color: Gray;"> </span><span style="color: #00008b;">message</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">${antfile.dir}</span><span style="color: #8b0000;">"</span><span style="color: Olive;">/></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">echo</span><span style="color: Olive;">></span><span style="color: Gray;">${antfile2.dir}</span><span style="color: Olive;"></</span><span style="color: Green;">echo</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"></</span><span style="color: Green;">target</span><span style="color: Olive;">></span><span style="color: Gray;"> </span></li>
<li><span style="color: Olive;"></</span><span style="color: Green;">project</span><span style="color: Olive;">></span></li></ol></div>
<p>ant.file这个属性是系统自带的,为当前运行的构建文件路径。<br />
明河这里将dirname和property进行比较,二者的输出有明显的区别,dirname只输出目录,property输出完成文件路径,如下图<br />
<a href="http://www.36ria.com/4534/2011-10-17-20-36-22" rel="attachment wp-att-4535"><img src="http://www.36ria.com/wp-content/uploads/2011/10/2011-10-17-20-36-22.png" alt="" title="2011-10-17 20-36-22" width="358" height="149" class="alignnone size-full wp-image-4535" /></a></p>
<h3>7.available:验证文件、目录、类的存在性</h3>
<p>available任务在防止ant构建时因为文件或目录不存在导致的错误时非常有用。</p>
<table border="0" cellspacing="0" cellpadding="0" class="tab1">
<colgroup>
<col width="160">
<col>
</colgroup>
<thead>
<tr>
<td valign="top">
<p><strong>属性</strong></p>
</td>
<td valign="top">
<p><strong>说明</strong></p>
</td>
</tr>
</thead>
<tbody>
<tr>
<td valign="top">
<p><strong>property</strong></p>
</td>
<td valign="top">
<p>属性名</p>
</td>
</tr>
<tr>
<td valign="top">
<p><strong>value</strong></p>
</td>
<td valign="top">
<p>属性值,默认为true</p>
</td>
</tr>
<tr>
<td valign="top">
<p><strong>file</strong></p>
</td>
<td valign="top">
<p>需要验证的文件</p>
</td>
</tr>
<tr>
<td valign="top">
<p><strong>type</strong></p>
</td>
<td valign="top">
<p>file的类型,验证目录(type=”dir”) or 验证文件 (type=”file”)</p>
</td>
</tr>
</tbody>
</table>
<p>示例代码</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: Olive;"><?</span><span style="color: Green;">xml</span><span style="color: Gray;"> </span><span style="color: #00008b;">version</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">1.0</span><span style="color: #8b0000;">"</span><span style="color: Olive;">?></span></li>
<li><span style="color: Olive;"><</span><span style="color: Green;">project</span><span style="color: Gray;"> </span><span style="color: #00008b;">name</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">test</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: #00008b;">default</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">build</span><span style="color: #8b0000;">"</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">target</span><span style="color: Gray;"> </span><span style="color: #00008b;">name</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">build</span><span style="color: #8b0000;">"</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">dirname</span><span style="color: Gray;"> </span><span style="color: #00008b;">property</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">antfile.dir</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: #00008b;">file</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">${ant.file}</span><span style="color: #8b0000;">"</span><span style="color: Olive;">/></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">property</span><span style="color: Gray;"> </span><span style="color: #00008b;">name</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">ui</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: #00008b;">location</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">${antfile.dir}/ui.js</span><span style="color: #8b0000;">"</span><span style="color: Olive;">/></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">available</span><span style="color: Gray;"> </span><span style="color: #00008b;">file</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">${ui}</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: #00008b;">type</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">file</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: #00008b;">property</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">is</span><span style="color: #8b0000;">"</span><span style="color: Olive;">/></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">echo</span><span style="color: Olive;">></span><span style="color: Gray;">${is}</span><span style="color: Olive;"></</span><span style="color: Green;">echo</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"></</span><span style="color: Green;">target</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span></li>
<li><span style="color: Olive;"></</span><span style="color: Green;">project</span><span style="color: Olive;">></span></li></ol></div>
<p>available的value值永远为一个布尔值。</p>
<h3>8.get:从url中获取文件</h3>
<p>get用于快速将远程文件保存到指定位置,不止支持http:协议,ftp:,jar:也都是可以的。</p>
<table border="0" cellspacing="0" cellpadding="0" class="tab1">
<colgroup>
<col width="160">
<col>
</colgroup>
<thead>
<tr>
<td valign="top">
<p><strong>属性</strong></p>
</td>
<td valign="top">
<p><strong>说明</strong></p>
</td>
</tr>
</thead>
<tbody>
<tr>
<td valign="top">
<p><strong>src</strong></p>
</td>
<td valign="top">
<p>源url</p>
</td>
</tr>
<tr>
<td valign="top">
<p><strong>dest</strong></p>
</td>
<td valign="top">
<p>目标路径</p>
</td>
</tr>
<tr>
<td valign="top">
<p><strong>verbose</strong></p>
</td>
<td valign="top">
<p>是否显示下载进度(100 Kb显示一个“.”)</p>
</td>
</tr>
<tr>
<td valign="top">
<p><strong>usetimestamp</strong></p>
</td>
<td valign="top">
<p>显示最后修改时间</p>
</td>
</tr>
<tr>
<td valign="top">
<p><strong>username</strong></p>
</td>
<td valign="top">
<p>‘BASIC’验证页面的用户名</p>
</td>
</tr>
<tr>
<td valign="top">
<p><strong>password</strong></p>
</td>
<td valign="top">
<p>‘BASIC’验证页面的密码</p>
</td>
</tr>
</tbody>
</table>
<p>来看个demo代码:</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: Olive;"><?</span><span style="color: Green;">xml</span><span style="color: Gray;"> </span><span style="color: #00008b;">version</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">1.0</span><span style="color: #8b0000;">"</span><span style="color: Olive;">?></span></li>
<li><span style="color: Olive;"><</span><span style="color: Green;">project</span><span style="color: Gray;"> </span><span style="color: #00008b;">name</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">test</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: #00008b;">default</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">build</span><span style="color: #8b0000;">"</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">target</span><span style="color: Gray;"> </span><span style="color: #00008b;">name</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">build</span><span style="color: #8b0000;">"</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">dirname</span><span style="color: Gray;"> </span><span style="color: #00008b;">property</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">antfile.dir</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: #00008b;">file</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">${ant.file}</span><span style="color: #8b0000;">"</span><span style="color: Olive;">/></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">get</span><span style="color: Gray;"> </span><span style="color: #00008b;">src</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">http://www.36ria.com/</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: #00008b;">dest</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">${antfile.dir}/36ria-index.html</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: #00008b;">verbose</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">true</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: #00008b;">usetimestamp</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">true</span><span style="color: #8b0000;">"</span><span style="color: Olive;">/></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"></</span><span style="color: Green;">target</span><span style="color: Olive;">></span><span style="color: Gray;"> </span></li>
<li><span style="color: Olive;"></</span><span style="color: Green;">project</span><span style="color: Olive;">></span></li></ol></div>
<p>运行后,如下图:<br />
<a href="http://www.36ria.com/4534/2011-10-18-11-41-55" rel="attachment wp-att-4541"><img src="http://www.36ria.com/wp-content/uploads/2011/10/2011-10-18-11-41-55.png" alt="" title="2011-10-18 11-41-55" width="454" height="133" class="alignnone size-full wp-image-4541" /></a><br />
如果要把一批url保存下来该如何处理呢?</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: Olive;"><</span><span style="color: Green;">get</span><span style="color: Gray;"> </span><span style="color: #00008b;">dest</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">downloads</span><span style="color: #8b0000;">"</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">url</span><span style="color: Gray;"> </span><span style="color: #00008b;">url</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">http://ant.apache.org/index.html</span><span style="color: #8b0000;">"</span><span style="color: Olive;">/></span><span style="color: Gray;"> </span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">url</span><span style="color: Gray;"> </span><span style="color: #00008b;">url</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">http://ant.apache.org/faq.html</span><span style="color: #8b0000;">"</span><span style="color: Olive;">/></span></li>
<li><span style="color: Olive;"></</span><span style="color: Green;">get</span><span style="color: Olive;">></span></li></ol></div>
<h3>9.local:增加个局部属性</h3>
<p>为了更好说明local用法,明河先贴出demo代码:</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: Olive;"><</span><span style="color: Green;">property</span><span style="color: Gray;"> </span><span style="color: #00008b;">name</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">foo</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: #00008b;">value</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">foo</span><span style="color: #8b0000;">"</span><span style="color: Olive;">/></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">target</span><span style="color: Gray;"> </span><span style="color: #00008b;">name</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">step1</span><span style="color: #8b0000;">"</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">echo</span><span style="color: Olive;">></span><span style="color: Gray;">Before local: foo is ${foo}</span><span style="color: Olive;"></</span><span style="color: Green;">echo</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">local</span><span style="color: Gray;"> </span><span style="color: #00008b;">name</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">foo</span><span style="color: #8b0000;">"</span><span style="color: Olive;">/></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">property</span><span style="color: Gray;"> </span><span style="color: #00008b;">name</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">foo</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: #00008b;">value</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">bar</span><span style="color: #8b0000;">"</span><span style="color: Olive;">/></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">echo</span><span style="color: Olive;">></span><span style="color: Gray;">After local: foo is ${foo}</span><span style="color: Olive;"></</span><span style="color: Green;">echo</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"></</span><span style="color: Green;">target</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">target</span><span style="color: Gray;"> </span><span style="color: #00008b;">name</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">step2</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: #00008b;">depends</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">step1</span><span style="color: #8b0000;">"</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">echo</span><span style="color: Olive;">></span><span style="color: Gray;">In step2: foo is ${foo}</span><span style="color: Olive;"></</span><span style="color: Green;">echo</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"></</span><span style="color: Green;">target</span><span style="color: Olive;">></span></li></ol></div>
<p>上述代码会输出如下内容:</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: Gray;">step1:</span></li>
<li><span style="color: Gray;"> [echo] Before local: foo is foo</span></li>
<li><span style="color: Gray;"> [echo] After local: foo is bar</span></li>
<li><span style="color: Gray;"> </span></li>
<li><span style="color: Gray;">step2:</span></li>
<li><span style="color: Gray;"> [echo] In step2: foo is foo</span></li></ol></div>
<p>在step1目标中我们定义了<local name="foo"/>,类似编程语言中的局部变量,改变后foo的输出值为bar,不再是原来定义的foo,有意思的是原来的
<property name="foo" value="foo"/>值不会发生改变,step2目标验证了这一点。也就是说在step1内部定义了local 后,foo这个property的修改不会影响外部property的值。<br />
local这个任务在sequential(循环)中非常常用,讲到sequential时再演示其用法。</p>
<h3>10.touch:创建文件,并可以修改文件修改时间</h3>
<table border="0" cellspacing="0" cellpadding="0" class="tab1">
<colgroup>
<col width="160">
<col>
</colgroup>
<thead>
<tr>
<td valign="top">
<p><strong>属性</strong></p>
</td>
<td valign="top">
<p><strong>说明</strong></p>
</td>
</tr>
</thead>
<tbody>
<tr>
<td valign="top">
<p><strong>file</strong></p>
</td>
<td valign="top">
<p>文件名称</p>
</td>
</tr>
<tr>
<td valign="top">
<p><strong>datetime</strong></p>
</td>
<td valign="top">
<p>指定文件修改时间</p>
</td>
</tr>
</tbody>
</table>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: Olive;"><</span><span style="color: Green;">touch</span><span style="color: Gray;"> </span><span style="color: #00008b;">file</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">myfile</span><span style="color: #8b0000;">"</span><span style="color: Olive;">/></span></li></ol></div>
<p>创建一个myfile文件,最后修改时间为当前时间。</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: Olive;"><</span><span style="color: Green;">touch</span><span style="color: Gray;"> </span><span style="color: #00008b;">file</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">myfile</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: #00008b;">datetime</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">18/10/2010 2:02 pm</span><span style="color: #8b0000;">"</span><span style="color: Olive;">/></span></li></ol></div>
<p>创建一个myfile文件,最后修改时间为18/10/2010 2:02 pm。</p>
</div>
</div>
</div>
<div class="bb-item" id="property">
<div class="content J_Content">
<div class="scroller">
<h2>property标签</h2>
<p>property(属性)这个标签很常用,当你在build.xml中定义了property,任务可以随意的引用该property,比如以下代码:</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: Olive;"><</span><span style="color: Green;">property</span><span style="color: Gray;"> </span><span style="color: #00008b;">name</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">author</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: #00008b;">value</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">minghe</span><span style="color: #8b0000;">"</span><span style="color: Olive;">/></span></li>
<li><span style="color: Gray;"> </span></li>
<li><span style="color: Olive;"><</span><span style="color: Green;">target</span><span style="color: Gray;"> </span><span style="color: #00008b;">name</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">test</span><span style="color: #8b0000;">"</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">echo</span><span style="color: Olive;">></span><span style="color: Gray;">${author}</span><span style="color: Olive;"></</span><span style="color: Green;">echo</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span></li>
<li><span style="color: Olive;"></</span><span style="color: Green;">target</span><span style="color: Olive;">></span></li></ol></div>
<p>当你要引入property,只要使用<strong>${property}</strong>语法即可。</p>
<h3>properties文件的使用</h3>
<p>考虑以下需求:build.xml需要提供给第三方使用,第三方本机的代码路径一般都不一样,如果让第三方自己去修改build.xml的路径配置(假如在你的build.xml中有类似
<property name="assets.dir" location=""/>的定义),正好该用户不懂得ant,那么面对build.xml,他将无所适从。能不能将配置独立成一个文件,用户只要改那个配置文件即可呢?</p>
<p>ant的.properties文件恰恰解决这个需求。</p>
<p>在build.xml同级目录下建立个build.properties(文件名任意);</p>
<p>键入如下示例代码:</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: Blue;">assets</span><span style="color: Gray;">.</span><span style="color: Blue;">dir</span><span style="color: Gray;"> = </span><span style="color: Blue;">d</span><span style="color: Gray;">:\</span><span style="color: Blue;">www</span><span style="color: Gray;">\</span><span style="color: Blue;">htdocs</span><span style="color: Gray;">\</span><span style="color: Blue;">ant</span><span style="color: Gray;">-</span><span style="color: Blue;">demo</span></li></ol></div>
<p>打开你的build.xml,插入如下代码:</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: Olive;"><</span><span style="color: Green;">property</span><span style="color: Gray;"> </span><span style="color: #00008b;">file</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">build.properties</span><span style="color: #8b0000;">"</span><span style="color: Olive;">/></span></li></ol></div>
<p>property的<strong>file</strong>属性指向<strong>build.properties</strong>文件,那么ant在执行build.xml前会去找这个文件,build.properties内的属性会覆盖build.xml内的同名属性。</p>
<p>假设你的build.xml有如下property:</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: Olive;"><</span><span style="color: Green;">property</span><span style="color: Gray;"> </span><span style="color: #00008b;">name</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">assets.dir</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: #00008b;">location</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">c:\demo</span><span style="color: #8b0000;">"</span><span style="color: Olive;">/></span></li></ol></div>
<p>你可以试下<echo>${assets.dir}</echo>,输出的将是build.properties文件内property值。</p>
<h3>value属性和location属性的区别</h3>
<p>这二个属性很容易混淆,不少朋友向明河询问,有了value,为什么还需要location呢?二者的作用不是一样的吗?</p>
<p>是的,value和location的功能是接近的,都是property的值,但有些小的区别,如果你的property存储的是路径,那么明河推荐使用location属性,location属性会对路径进行转换,永远返回绝对路径形式。来看实际代码:</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: Olive;"><</span><span style="color: Green;">dirname</span><span style="color: Gray;"> </span><span style="color: #00008b;">property</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">current.dir</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: #00008b;">file</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">${ant.file}</span><span style="color: #8b0000;">"</span><span style="color: Olive;">/></span></li>
<li><span style="color: Olive;"><</span><span style="color: Green;">property</span><span style="color: Gray;"> </span><span style="color: #00008b;">name</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">assets.dir</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: #00008b;">location</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">${current.dir}/2.0/</span><span style="color: #8b0000;">"</span><span style="color: Olive;">/></span></li>
<li><span style="color: Olive;"><</span><span style="color: Green;">property</span><span style="color: Gray;"> </span><span style="color: #00008b;">name</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">assets.dir2</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: #00008b;">value</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">${current.dir}/2.0/</span><span style="color: #8b0000;">"</span><span style="color: Olive;">/></span></li>
<li><span style="color: Olive;"><</span><span style="color: Green;">target</span><span style="color: Gray;"> </span><span style="color: #00008b;">name</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">location</span><span style="color: #8b0000;">"</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">echo</span><span style="color: Olive;">></span><span style="color: Gray;">location:${assets.dir}</span><span style="color: Olive;"></</span><span style="color: Green;">echo</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">echo</span><span style="color: Olive;">></span><span style="color: Gray;">value:${assets.dir2}</span><span style="color: Olive;"></</span><span style="color: Green;">echo</span><span style="color: Olive;">></span></li>
<li><span style="color: Olive;"></</span><span style="color: Green;">target</span><span style="color: Olive;">></span></li></ol></div>
<p>输出的结果如下:<br />
<a href="http://www.36ria.com/4584/2011-11-3-18-43-07" rel="attachment wp-att-4586"><img src="http://www.36ria.com/wp-content/uploads/2011/11/2011-11-3-18-43-07.png" alt="" title="2011-11-3 18-43-07" width="467" height="160" class="alignnone size-full wp-image-4586" /></a><br />
留意标黄部分的差异,当你使用location属性时,值内所有的“/”都会更换为“\”(即绝对路径的形式),而且还会去掉路径中多余的“/”。所以当你使用location属性存储路径信息时更为安全。</p>
</div>
</div>
</div>
<div class="bb-item" id="dataType">
<div class="content J_Content">
<div class="scroller">
<h2>dataType的用法</h2>
<p>这是ant理论部分的最后一章,也是非常重要的一章,明河将介绍ant中常用的几种dataType的用法。<br />
dataType可以理解为复杂数据集合,比如特定规则的文件列表集合。</p>
<h4>ant的所有dataType标签</h4>
<ul>
<li><strong>fileset</strong>:定义一个文件集合列表,这些文件必须确实存在</li>
<li><strong>filelist</strong>:定义一个文件集合列表,这些文件无需确实存在</li>
<li><strong>path</strong>:以某种在不同操作系统间可移植的方式指定路径</li>
<li><strong>patternset</strong>:将一组模式分组在一起</li>
<li><strong>argument</strong>:对于由一个ant构建文件调用的程序,向其传递命令行参数(标签名是arg)</li>
<li><strong>filterlist</strong>:将一组过滤器分组在一起</li>
<li><strong>mapper</strong>:定义一组输入文件和一组输出文件间的复杂关系</li>
<li><strong>environment</strong>:于由一个ant构建文件调用的程序,向其传递环境变量</li>
</ul>
<p>必须掌握的是:<strong>fileset</strong>、<strong>filelist</strong>、<strong>path</strong>、<strong>argument</strong>、<strong>patternset</strong>。</p>
<ul class="tow-columns clearfix">
<li class="l"><a href="http://www.36ria.com/wp-content/plugins/download-monitor/download.php?id=223" title="名称:ant的demo,下载次数:175,文件大小:38.94 kB" class="btn-download">点此下载</a></li>
<li class="l"></li>
</ul>
<h4>fileset</h4>
<p>fileset和filelist(下面会讲到),功能上非常相近,都是用于获取一组文件列表,二者的不同之处在于fileset内的文件必须存在,filelist则没这要求;fileset的属性也比filelist更为的丰富,所以功能上更为的强大,一般使用fileset来获取文件。</p>
<table border="0" cellspacing="0" cellpadding="0" class="tab1">
<colgroup>
<col width="160">
<col>
</colgroup>
<thead>
<tr>
<td valign="top">
<p><strong>属性</strong></p>
</td>
<td valign="top">
<p><strong>说明</strong></p>
</td>
</tr>
</thead>
<tbody>
<tr>
<td valign="top">
<p><strong>dir</strong></p>
</td>
<td valign="top">
<p>fileset的基目录</p>
</td>
</tr>
<tr>
<td valign="top">
<p><strong>dir</strong></p>
</td>
<td valign="top">
<p>fileset的基目录</p>
</td>
</tr>
<tr>
<td valign="top">
<p><strong>casesensitive</strong></p>
</td>
<td valign="top">
<p>如果为false,那么匹配文件名时不区分大小写,默认为true</p>
</td>
</tr>
<tr>
<td valign="top">
<p><strong>defaultexcludes</strong></p>
</td>
<td valign="top">
<p>是否使用默认的排除模式,默认为true。默认的排除模式会把一些版本控制的文件夹或文件排除</p>
</td>
</tr>
<tr>
<td valign="top">
<p><strong>excludes</strong></p>
</td>
<td valign="top">
<p>排除指定的文件列表(用逗号隔开)</p>
</td>
</tr>
<tr>
<td valign="top">
<p><strong>excludesfile</strong></p>
</td>
<td valign="top">
<p>排除指定的文件</p>
</td>
</tr>
<tr>
<td valign="top">
<p><strong>includes</strong></p>
</td>
<td valign="top">
<p>需要包含的文件列表(用逗号隔开)</p>
</td>
</tr>
<tr>
<td valign="top">
<p><strong>includesfile</strong></p>
</td>
<td valign="top">
<p>包含指定的文件</p>
</td>
</tr>
</tbody>
</table>
<p>接下来来看几个demo,假设demo目录如图所示:<br />
<a href="http://www.36ria.com/4591/uploader-dir" rel="attachment wp-att-4629"><img src="http://www.36ria.com/wp-content/uploads/2011/11/uploader-dir.png" alt="" title="uploader-dir" width="204" height="418" class="alignnone size-full wp-image-4629" /></a></p>
<h5>任务1:合并uploader目录下的所有文件</h5>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: Olive;"><?</span><span style="color: Green;">xml</span><span style="color: Gray;"> </span><span style="color: #00008b;">version</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">1.0</span><span style="color: #8b0000;">"</span><span style="color: Olive;">?></span></li>
<li><span style="color: Olive;"><</span><span style="color: Green;">project</span><span style="color: Gray;"> </span><span style="color: #00008b;">name</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">uploader</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: #00008b;">default</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">build-all</span><span style="color: #8b0000;">"</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: #ffa500;"><!--基目录--></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">dirname</span><span style="color: Gray;"> </span><span style="color: #00008b;">property</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">current.dir</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: #00008b;">file</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">${ant.file.uploader}</span><span style="color: #8b0000;">"</span><span style="color: Olive;">/></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">property</span><span style="color: Gray;"> </span><span style="color: #00008b;">name</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">uploader.dir</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: #00008b;">location</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">${current.dir}/uploader</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: Olive;">/></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">target</span><span style="color: Gray;"> </span><span style="color: #00008b;">name</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">build-all</span><span style="color: #8b0000;">"</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">echo</span><span style="color: Olive;">></span><span style="color: Gray;">dir:${current.dir}</span><span style="color: Olive;"></</span><span style="color: Green;">echo</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">concat</span><span style="color: Gray;"> </span><span style="color: #00008b;">destfile</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">uploader.js</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: #00008b;">encoding</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">utf8</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: #00008b;">outputencoding</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">utf8</span><span style="color: #8b0000;">"</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">fileset</span><span style="color: Gray;"> </span><span style="color: #00008b;">dir</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">${uploader.dir}</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: #00008b;">includes</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">**/*.js</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: Olive;">/></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"></</span><span style="color: Green;">concat</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"></</span><span style="color: Green;">target</span><span style="color: Olive;">></span></li>
<li><span style="color: Olive;"></</span><span style="color: Green;">project</span><span style="color: Olive;">></span></li></ol></div>
<p>concat(合并)这个任务标签,明河之前有讲过了,与之前写的demo不同的是,concat内增加了fileset。由于我们的需求是合并uploader目录下的所有js,所以uploader下文件不少,明显不可能单独一个个写path,这时候就需要用到fileset,获取文件列表集合。</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: Olive;"><</span><span style="color: Green;">fileset</span><span style="color: Gray;"> </span><span style="color: #00008b;">dir</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">${uploader.dir}</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: #00008b;">includes</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">**/*.js</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: Olive;">/></span></li></ol></div>
<p>fileset会获取${uploader.dir}(该属性引用指向uploader目录)下所有的js,通过<strong>includes=”**/*.js”</strong>包含所有js。<br />
也许你会对<strong>**/*</strong>感到疑惑,明河下面做个说明。</p>
<h5>包含和排除模式语法:</h5>
<ul>
<li><strong>*</strong>:匹配0或多个字符,比如*.js匹配minghe.js、taobao.js但不匹配minghe.css</li>
<li><strong>?</strong>:匹配1个字符,比如mingh?.js,匹配minghe.js、minghg.js,但不匹配minghe36.js</li>
<li><strong>**</strong>:匹配0或多个目录,比如/minghe/**,匹配/minghe/下的任意目录,**/*.js匹配任意目录下的所有js文件</li>
</ul>
<h5>使用patternset标签</h5>
<p>除了使用属性外,fileset还支持0到n个嵌套<strong>patternset</strong>元素,比如<code>exclude</code>、<code>include</code>等,关于patternset会在下面讲解到,这里先贴出修改后的demo。</p>
<div class="hl-surround"><ol class="hl-main ln-show" title="Double click to hide line number." ondblclick = "linenumber(this)"><li class="hl-firstline"><span style="color: Olive;"><</span><span style="color: Green;">target</span><span style="color: Gray;"> </span><span style="color: #00008b;">name</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">build-all2</span><span style="color: #8b0000;">"</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">echo</span><span style="color: Olive;">></span><span style="color: Gray;">build-all2</span><span style="color: Olive;"></</span><span style="color: Green;">echo</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">concat</span><span style="color: Gray;"> </span><span style="color: #00008b;">destfile</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">uploader2.js</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: #00008b;">encoding</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">utf8</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: #00008b;">outputencoding</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">utf8</span><span style="color: #8b0000;">"</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">fileset</span><span style="color: Gray;"> </span><span style="color: #00008b;">dir</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">${uploader.dir}</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">include</span><span style="color: Gray;"> </span><span style="color: #00008b;">name</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">**/*.js</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: Olive;">/></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"><</span><span style="color: Green;">exclude</span><span style="color: Gray;"> </span><span style="color: #00008b;">name</span><span style="color: Gray;">=</span><span style="color: #8b0000;">"</span><span style="color: Red;">demo/*.js</span><span style="color: #8b0000;">"</span><span style="color: Gray;"> </span><span style="color: Olive;">/></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"></</span><span style="color: Green;">fileset</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"></</span><span style="color: Green;">concat</span><span style="color: Olive;">></span></li>
<li><span style="color: Gray;"> </span><span style="color: Olive;"></</span><span style="color: Green;">target</span><span style="color: Olive;">></span></li></ol></div>
<p>这里的demo代码,与上一个demo相比,增加了一个排除文件模式,demo目录下的js文件,显然我们不需要,可以通过<code>exclude</code>标签予以排除</p>
<h4>filelist</h4>
<p>filelist通常与dependset任务一同使用,dependset任务用于将一个或多个源文件和1个或多个目标文件相比较,如果源文件存在更新或者删除,那么所有目标文件将将被删除。dependset用于确保文件的依赖性。</p>
<h5>filelist的属性</h5>
<table border="0" cellspacing="0" cellpadding="0" class="tab1">
<colgroup>
<col width="160">
<col>
</colgroup>
<thead>
<tr>
<td valign="top">
<p><strong>属性</strong></p>
</td>
<td valign="top">
<p><strong>说明</strong></p>
</td>
</tr>
</thead>
<tbody>
<tr>
<td valign="top">
<p><strong>dir</strong></p>
</td>
<td valign="top">
<p>fileset的基目录</p>
</td>
</tr>
<tr>
<td valign="top">
<p><strong>files</strong></p>
</td>
<td valign="top">
<p>用逗号隔开的文件列表</p>
</td>
</tr>
<tr>
<td valign="top">
<p><strong>refid</strong></p>
</td>
<td valign="top">
<p>对某处定义的一个filelist的引用,这对于希望多次复用一个定义的文件列表,非常有用。</p>
</td>
</tr>
</tbody>
</table>
<p>filelist的使用率不高,明河这里偷个懒,不再制作个独立的demo。 </p>
<h4>path</h4>
<p>path在java打包编译中常用到,可以以属性(多个路径用冒号或分号隔开)或嵌套元素的方式。<br />
path用于转换路径为当前用户操作系统可兼容的路径。(path dataType并不只有<code>
path</code>元素,还有<code>classpath</code>等形式标签)。</p>
<h5>当path以标签的形式出现时,拥有以下属性:</h5>
<table border="0" cellspacing="0" cellpadding="0" class="tab1">
<colgroup>
<col width="160">
<col>
</colgroup>
<thead>
<tr>
<td valign="top">
<p><strong>属性</strong></p>
</td>
<td valign="top">
<p><strong>说明</strong></p>
</td>
</tr>
</thead>
<tbody>
<tr>
<td valign="top">
<p><strong>location</strong></p>
</td>
<td valign="top">
<p>表示一个文件或目录</p>
</td>
</tr>
<tr>
<td valign="top">
<p><strong>path</strong></p>
</td>