本文是对Sun网站的文章Developing Web Application with JavaServer Faces的翻译,如有转载,请声明出处!
创建自定义的JSF Web应用程序
1. 创建如下所示的目录结构:
c:\jsf-1_1\samples\MyApp
\src
YourBeans.java
\web
YourJSP-pages.jsp
AnyImages.gif
\WEB-INF
web.xml
faces-config.xml
2. 创建JSP页面和Bean类
3. 根据需要修改web.xml和faces-config.xml文件
4. 修改JavaServer Faces RI的发布包中的build.properties和build.xml文件,设置服务器的路径。以便使用Ant工具将工程打包发布。下面是一个build.xml文件的样例:
<project name="MyFirst" default="build.war" basedir=".">
<property file="../build.properties"/>
<!-- Configure the context path for this application -->
<property name="context.path" value="/jsf-MyFirst"/>
<property name="example" value="jsf-MyFirst" />
<property name="build" value="${basedir}/build" />
<path id="classpath">
<pathelement location="${commons-beanutils.jar}"/>
<pathelement location="${commons-collections.jar}"/>
<pathelement location="${commons-digester.jar}"/>
<pathelement location="${commons-logging.jar}"/>
<pathelement location="${jsf-api.jar}"/>
<pathelement location="${jsf-impl.jar}"/>
<pathelement location="${jstl.jar}"/>
<pathelement location="${build}/${example}/WEB-INF/classes"/>
<pathelement location="${servlet.jar}"/>
</path>
<target name="clean" >
<delete dir="${build}" />
<delete dir="${context.path}" />
</target>
<target name="prepare" description="Create build directories.">
<mkdir dir="${build}/${example}" />
<mkdir dir="${build}/${example}/WEB-INF" />
<mkdir dir="${build}/${example}/WEB-INF/classes" />
<mkdir dir="${build}/${example}/WEB-INF/lib" />
</target>
<!-- Executable Targets -->
<target name="build" depends="prepare,deploy.copyJars"
description="Compile Java files and copy static files." >
<javac srcdir="src" destdir="${build}/${example}/WEB-INF/classes">
<include name="**/*.java" />
<classpath refid="classpath"/>
</javac>
<copy todir="${build}/${example}/WEB-INF">
<fileset dir="web/WEB-INF">
<include name="*.xml" />
</fileset>
</copy>
<copy todir="${build}/${example}/">
<fileset dir="web">
<include name="*.html" />
<include name="*.gif" />
<include name="*.jpg" />
<include name="*.jsp" />
<include name="*.xml" />
</fileset>
</copy>
<copy todir="${build}/${example}/WEB-INF/classes/${example}" >
<fileset dir="web" >
<include name="*properties"/>
</fileset>
</copy>
</target>
<target name="deploy.copyJars" if="build.standalone">
<copy todir="${build}/${example}/WEB-INF/lib" file="${commons-beanutils.jar}" />
<copy todir="${build}/${example}/WEB-INF/lib" file="${commons-collections.jar}" />
<copy todir="${build}/${example}/WEB-INF/lib" file="${commons-logging.jar}" />
<copy todir="${build}/${example}/WEB-INF/lib" file="${commons-digester.jar}" />
<copy todir="${build}/${example}/WEB-INF/lib" file="${jsf-api.jar}" />
<copy todir="${build}/${example}/WEB-INF/lib" file="${jsf-impl.jar}" />
<copy todir="${build}/${example}/WEB-INF/lib" file="${jstl.jar}" />
<copy todir="${build}/${example}/WEB-INF/lib" file="${standard.jar}" />
</target>
<target name="build.war" depends="build">
<!-- create a war file for distribution -->
<jar jarfile="${example}.war" basedir="${build}/${example}"/>
<copy todir=".." file="${example}.war" />
<delete file="${example}.war" />
</target>
</project>
5. 根据需要修改上述的build.xml文件,然后运行ant命令,创建war文件。
6. 将war文件发布到应用程序服务器或者Servlet容器,启动服务。
发表于 @ 2008年06月10日 22:11:00|编辑|收藏