![](/Images/OutliningIndicators/None.gif)
2
![](/Images/OutliningIndicators/None.gif)
3
![](/Images/OutliningIndicators/None.gif)
4
![](/Images/OutliningIndicators/None.gif)
5
![](/Images/OutliningIndicators/None.gif)
6
![](/Images/OutliningIndicators/None.gif)
7
![](/Images/OutliningIndicators/None.gif)
8
![](/Images/OutliningIndicators/None.gif)
9
![](/Images/OutliningIndicators/None.gif)
10
![](/Images/OutliningIndicators/None.gif)
11
![](/Images/OutliningIndicators/None.gif)
12
![](/Images/OutliningIndicators/None.gif)
13
![](/Images/OutliningIndicators/None.gif)
14
![](/Images/OutliningIndicators/None.gif)
15
![](/Images/OutliningIndicators/None.gif)
16
![](/Images/OutliningIndicators/None.gif)
17
![](/Images/OutliningIndicators/None.gif)
18
![](/Images/OutliningIndicators/None.gif)
19
![](/Images/OutliningIndicators/None.gif)
20
![](/Images/OutliningIndicators/None.gif)
21
![](/Images/OutliningIndicators/None.gif)
22
![](/Images/OutliningIndicators/None.gif)
23
![](/Images/OutliningIndicators/None.gif)
24
![](/Images/OutliningIndicators/None.gif)
25
![](/Images/OutliningIndicators/None.gif)
26
![](/Images/OutliningIndicators/None.gif)
27
![](/Images/OutliningIndicators/None.gif)
28
![](/Images/OutliningIndicators/None.gif)
29
![](/Images/OutliningIndicators/None.gif)
30
![](/Images/OutliningIndicators/None.gif)
31
![](/Images/OutliningIndicators/None.gif)
32
![](/Images/OutliningIndicators/None.gif)
33
![](/Images/OutliningIndicators/None.gif)
34
![](/Images/OutliningIndicators/None.gif)
35
![](/Images/OutliningIndicators/None.gif)
36
![](/Images/OutliningIndicators/None.gif)
37
![](/Images/OutliningIndicators/None.gif)
38
![](/Images/OutliningIndicators/None.gif)
39
![](/Images/OutliningIndicators/None.gif)
40
![](/Images/OutliningIndicators/None.gif)
41
![](/Images/OutliningIndicators/None.gif)
42
![](/Images/OutliningIndicators/None.gif)
43
![](/Images/OutliningIndicators/None.gif)
44
![](/Images/OutliningIndicators/None.gif)
45
![](/Images/OutliningIndicators/None.gif)
![](/Images/dot.gif)
46
![](/Images/OutliningIndicators/None.gif)
47
![](/Images/OutliningIndicators/None.gif)
48
![](/Images/OutliningIndicators/None.gif)
49
![](/Images/OutliningIndicators/None.gif)
50
![](/Images/OutliningIndicators/None.gif)
51
![](/Images/OutliningIndicators/None.gif)
52
![](/Images/OutliningIndicators/None.gif)
53
![](/Images/OutliningIndicators/None.gif)
54
![](/Images/OutliningIndicators/None.gif)
55
![](/Images/OutliningIndicators/None.gif)
56
![](/Images/OutliningIndicators/None.gif)
57
![](/Images/OutliningIndicators/None.gif)
58
![](/Images/OutliningIndicators/None.gif)
59
![](/Images/OutliningIndicators/None.gif)
![](/Images/dot.gif)
60
![](/Images/OutliningIndicators/None.gif)
61
![](/Images/OutliningIndicators/None.gif)
62
![](/Images/OutliningIndicators/None.gif)
63
![](/Images/OutliningIndicators/None.gif)
64
![](/Images/OutliningIndicators/None.gif)
65
![](/Images/OutliningIndicators/None.gif)
66
![](/Images/OutliningIndicators/None.gif)
67
![](/Images/OutliningIndicators/None.gif)
68
![](/Images/OutliningIndicators/None.gif)
69
![](/Images/OutliningIndicators/None.gif)
70
![](/Images/OutliningIndicators/None.gif)
71
![](/Images/OutliningIndicators/None.gif)
72
![](/Images/OutliningIndicators/None.gif)
73
![](/Images/OutliningIndicators/None.gif)
74
![](/Images/OutliningIndicators/None.gif)
75
![](/Images/OutliningIndicators/None.gif)
76
![](/Images/OutliningIndicators/None.gif)
77
![](/Images/OutliningIndicators/None.gif)
78
![](/Images/OutliningIndicators/None.gif)
79
![](/Images/OutliningIndicators/None.gif)
80
![](/Images/OutliningIndicators/None.gif)
81
![](/Images/OutliningIndicators/None.gif)
82
![](/Images/OutliningIndicators/None.gif)
83
![](/Images/OutliningIndicators/None.gif)
84
![](/Images/OutliningIndicators/None.gif)
85
![](/Images/OutliningIndicators/None.gif)
86
![](/Images/OutliningIndicators/None.gif)
87
![](/Images/OutliningIndicators/None.gif)
88
![](/Images/OutliningIndicators/None.gif)
89
![](/Images/OutliningIndicators/None.gif)
90
![](/Images/OutliningIndicators/None.gif)
91
![](/Images/OutliningIndicators/None.gif)
92
![](/Images/OutliningIndicators/None.gif)
93
![](/Images/OutliningIndicators/None.gif)
94
![](/Images/OutliningIndicators/None.gif)
95
![](/Images/OutliningIndicators/None.gif)
96
![](/Images/OutliningIndicators/None.gif)
97
![](/Images/OutliningIndicators/None.gif)
98
![](/Images/OutliningIndicators/None.gif)
99
![](/Images/OutliningIndicators/None.gif)
100
![](/Images/OutliningIndicators/None.gif)
101
![](/Images/OutliningIndicators/None.gif)
102
![](/Images/OutliningIndicators/None.gif)
103
![](/Images/OutliningIndicators/None.gif)
104
![](/Images/OutliningIndicators/None.gif)
105
![](/Images/OutliningIndicators/None.gif)
106
![](/Images/OutliningIndicators/None.gif)
107
![](/Images/OutliningIndicators/None.gif)
108
![](/Images/OutliningIndicators/None.gif)
109
![](/Images/OutliningIndicators/None.gif)
110
![](/Images/OutliningIndicators/None.gif)
111
![](/Images/OutliningIndicators/None.gif)
112
![](/Images/OutliningIndicators/None.gif)
113
![](/Images/OutliningIndicators/None.gif)
114
![](/Images/OutliningIndicators/None.gif)
115
![](/Images/OutliningIndicators/None.gif)
116
![](/Images/OutliningIndicators/None.gif)
117
![](/Images/OutliningIndicators/None.gif)
118
![](/Images/OutliningIndicators/None.gif)
119
![](/Images/OutliningIndicators/None.gif)
120
![](/Images/OutliningIndicators/None.gif)
121
![](/Images/OutliningIndicators/None.gif)
122
![](/Images/OutliningIndicators/None.gif)
123
![](/Images/OutliningIndicators/None.gif)
124
![](/Images/OutliningIndicators/None.gif)
125
![](/Images/OutliningIndicators/None.gif)
126
![](/Images/OutliningIndicators/None.gif)
127
![](/Images/OutliningIndicators/None.gif)
128
![](/Images/OutliningIndicators/None.gif)
129
![](/Images/OutliningIndicators/None.gif)
130
![](/Images/OutliningIndicators/None.gif)
131
![](/Images/OutliningIndicators/None.gif)
132
![](/Images/OutliningIndicators/None.gif)
133
![](/Images/OutliningIndicators/None.gif)
134
![](/Images/OutliningIndicators/None.gif)
135
![](/Images/OutliningIndicators/None.gif)
136
![](/Images/OutliningIndicators/None.gif)
137
![](/Images/OutliningIndicators/None.gif)
138
![](/Images/OutliningIndicators/None.gif)
139
![](/Images/OutliningIndicators/None.gif)
140
![](/Images/OutliningIndicators/None.gif)
141
![](/Images/OutliningIndicators/None.gif)
142
![](/Images/OutliningIndicators/None.gif)
143
![](/Images/OutliningIndicators/None.gif)
144
![](/Images/OutliningIndicators/None.gif)
145
![](/Images/OutliningIndicators/None.gif)
4.编写ANT构建文件
ANT是一个强大的开源构建工具,它可以快速地对整个WEB应用程序进行编译打包部署等工作,以目标的方式来管理不同的任务,ANT把建立一个WEB应用所需做的大量工作都集成在了一起统一地管理起来,这种方式大大地提高了应用构建的效率和灵活性.
针对本文所述的应用我编写了以下这个构建文件,文件名为build.xml:
project是整个构建文件的根,向下看就是属性定义,属性是一个名称/值对,所以property标签就有两个属性,一个是name,另一个是value,属性定义下面是path结点,这一段指定了在编译器编译的时候要用到的jar包的路径.在整个文件中有很多的${}符号,这个符号就是对属性的引用,大括号中是属性名称.
Jar包定义段之后就是各个目标的定义了,目标标签是<target>,目标标签主要用到的属性有name,depends.name指定目标的名称,depends指定目标的依赖特性,当A目标有一个depends=”B”属性是,就说明A的运行依赖于B,在运行A的时候如果没有运行B,ANT会自动地先运行B目标再运行A目标.
在这个文件中定义了6个目标.分别是:clean,init,compile,mkjar,deploy,runserver,其中clean目标用来清除产生的工作目录和过期的类和jar包.在构建前进行清理是一个好习惯.init是进行初始化,是用来建立一些在编译构建过程中需要的文件夹.compile目标就是进行JAVA文件的编译,mkjar目标是把编译后的类文件打成jar包,deploy是把编译好的类文件和jar包部署到WEB-INF中.最后一个目标就是运行TOMCAT服务器.
下面对一些用到的ANT标签进行说明:
<property name="propertyName" value="propertyValue" />:属性定义,name是属性名称,value是属性值
<javac destdir="build">
<classpath refid="build.classpath"></classpath>
<src path="webapp/src"></src>
</javac>:编译JAVA源文件,其子标签src指定要编译的源文件目录;classpath指定查找用户类文件的位置,功能与javac命令的-classpath参数相同.
<jar destfile="dest.jar" basedir="classes_dir" />:打jar包,destfile是jar包文件名,可以包含路径信息;basedir是要打包的class文件目录.也可以用下面的形式:
<jar destfile="dest.jar" basedir="classes_dir">
<manifest>
<attribute name="Built-By" value="${user.name}">
<attribute name="Main-class" value="MainClass">
</manifest>
</jar>
manifest子结点指定为jar包生成一个清单文件,manifest的子结点说明了清单文件中的内容,可见清单文件中的内容也是名称/值对.在上面定义了作者和主类.
<delete dir="${toBeDelete_dir}" /> :删除指定的目录
<mkdir dir="${buildDir}" />:新建目录
<copy file="src/test.java" tofile="src/testCopy.java" /> :复制文件并改名
<move file="src/test.java" tofile="src/testMove.java" /> :仅改名不复制(重命名)
<zip destfile=”test.zip” basedir=”toBeZipDir” />:压缩文件
<exec dir="${tomcathome}/bin" executable="${tomcathome}/bin/startup.bat" /> :执行外部文件.
把上面的构建文件内容复制到WEB应用的根目录下保存为build.xml.
5.编写BAT批处理文件
到现在为止,WEB应用程序部分就完成了.写BAT文件的目的就是把所有要进行的工作都集成起来.这一步不是必要的,但确实非常有用的.要执行本文的WEB应用可以运行如下的批处理文件:
SET ANT_HOME=F:\devSpace\Ant-
path=%ANT_HOME%\bin
SET PATH=%PATH%
call ant -f F:\workspace\JSFWebAppEx\build.xml runserver
第一句是设置ANT的HOME目录,第二句是设置ANT.exe的目录,最后一句就是调用ANT,-f参数是指定构建文件路径.runserver是构建文件中的目标名称,因为在本文的构建文件中,runserver依赖于deploy,deploy依赖于mkjar,mkjar依赖于compile,compile依赖于init,init依赖于clean,所以在ANT.EXE中指定运行runserver时,ANT会自动地从第一个目标开始运行.
把上面的批处理文件内容保存到WEB应用的根目录下的run.bat中.
6.运行WEB应用
当TOMCAT运行起来以后就可以在浏览器中观察结果了.注意:如果不知道HTTP的端口号,那么在输入URL以前请先在%TOMCAT_HOME%\conf\server.xml中查看HTTP的端口号.然后输入http://localhost:8888/JSFApp/faces/index.jsp(假设端口号是8888,WEB应用的虚拟根目录是JSFApp).