本文将介绍在ECLIPSE环境下开始JSF开发的整个过程,主要侧重在环境的配置,ANT工具的基本用法,并且用ANT进行简单的工程构建,本文也会介绍JSF的一些基本标签.
我先把整个过程分成若干个步骤:
安装ECLIPSE,ANT以及TOMCAT并设置环境变量 à 配置工程环境(JSF) à编写测试文件(jsp&java) à 编写ANT构建文件 à 编写BAT文件
1. 安装ECLIPSE,ANT以及TOMCAT并设置环境变量
在www.eclipse.org下载最新版本的ECLIPSE;ANT和TOMCAT可以在www.apache.org 下载到.假设这三个工具都是放在 F :\ 根目录下.将下载的ECLIPSE,ANT和TOMCAT解压后放在F:\根目录中.然后在“我的电脑”à属性à高级选项卡à环境变量à在环境变量中新建一个TOMCAT_HOME变量,其值为F:\Tomcat5.5;再另新建一个环境变量TOMCAT_BASE,其值为F:\Tomcat5.5;再设置ANT的环境变量,新建变量ANT_HOME,其值为F:\Ant-
2. 配置JSF工程环境
首先在ECLIPSE中建立一个Java Project,在这里我将其命名为JSFWEBAPP,并且在工程文件夹下建立目录结构如下图:
然后,在WEB-INF目录中新建一个XML文件web.xml,这个文件可以自己新建,也可以从%TOMCAT_HOME%\conf下复制。要进行JSF开发就必须要在web.xml目录中添加一段配置信息,如下:
![](/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)
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)
可以将上面一段配置信息直接复制到你的web.xml文件中.除了以上的配置以外,还要在TOMCAT中进行WEB应用的虚拟目录的配置,方法是在%TOMCAT_HOME%\conf\server.xml文件中添加:
<Context docBase="F:/workspace/JSFWebAppEx/webapp/web" path="/JSFApp" reloadable="true" workDir="f:\workspace\JSFWebAppEx\work"/>(docBase是WEB项目JSP页面文件所在目录,path是WEB项目的虚拟目录,work是编译后的JSP文件的存放目录)
也可以把这一段写在一个独立的XML文件中(XML文件的命名通常与WEB项目的名称相同,以便管理),并将其保存在%TOMCAT_HOME%\conf\Catalina\localhost下.
另外还要新建一个faces-config.xml文件,这个是支持JSF的配置文件.需要自己建立,其内容主要有两类基本配置,一类是页面导航规则,另一类是受管Bean的配置信息.下面给出一个配置例子:
![](/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)
注意:以上的配置信息都要放在<faces-config></faces-config>之中.
同样也可以把上面的配置格式套用(注意这里是套用不是复制,只是利用上面配置的格式,要根据自己的具体情况更改以上黑字部分)到自己的faces-config.xml中。在下面会详细说明以上配置的含义。
现在需要把支持JSF开发的若干个jar包放在web/WEB-INF/lib文件夹中. 下面是JSF开发相关jar包下载地址:
1).http://java.sun.com/j2ee/javaserverfaces/download.html 选择其中Reference Implementation 这个是JSF的开发包.
2).http://jakarta.apache.org/site/downloads/, 这里下载的是JSTL的开发包.
将上面的两类jar包下载下来并且复制到web/WEB-INF/lib中.
下面列出所有需要的jar包文件名:
commons-beanutils.jar
commons-collections.jar
commons-digester.jar
commons-logging.jar
jsf-api.jar
jsf-impl.jar
jstl.jar
standard.jar
(未完...)