Java EE 5 开发指南 - 前言

来源:互联网 发布:数据挖掘国际会议 编辑:程序博客网 时间:2024/06/08 15:44

 

Java EE 5 开发指南

 

前言

 

本文档是来自于不断更新的java.sun.com在线文档,如果发现有新版本,可以从以下网址下载最新版:

http://javadoc.allimant.org/

注意,如果希望查证最新版内容,请访问java.sun.com.

 

由于HTMLHelp文档的一些限制,以下内容会与原在线文档之间存在差异:

1.    Java Applets

大多数情况下,HTMLHelp可以运行没有嵌入在chm文件中的Java 1applet小程序,但需要将applets存放于chm相应的目录中,如果未能找到applet文件,可能页面中的无法显示出applet小程序。

2.    需要插件的内容

有些内容需要专用的插件支持,如PDF文件,这些内容在HTMLHelp格式文档中可能无法正确显示。

3.    重复的关键字

如果某个关键字在多处出现,那么在HTMLHelp文档中查找该关键字,可能会出现多处引用。

 

本文档用于对Java EE 5(Java平台企业级开发,Sun Java System Application Server Platform Edition 9.)感觉的编程人员,涵盖了所有在开发过程中需要用到的知识内容。

 

必备条件

在开发本指南内容之前,你需要掌握Java语言的基本知识,还需要了解与关系型数据库有关的内容,以及JDBC数据库开发接口。

 

如何使用本指南

Java EE 5平台是非常宠大的,本指南体现了这一点,在学习时,我们无需一次理解所有的概念和内容,指南中的内容已分为多个部分,帮助我们更容易地学习在知识体系上相关的内容。

本指南使用一个介绍性章节作为开场白,你应该在学习其它技术领域内容之前仔细阅读该内容。第一章节包含了Sun公司的Java服务器系统(版本9)附带的Java EE 5平台的架构及API知识。

当你在掌握了基础知识后,你可以选择学习以下五个技术领域的内容。每项内容都有可能与其它某些内容相关联,图1提供了一个学习的路标,帮助我们选择适合的学习路径。

1.         Web层技术:包括用于开发系统的表现层技术,也可以用于开发独立的Web程序;其中包括ServletJSPJavaServer Pages)、JSTLJavaServer Pages Standard Tag LIbrary)、JSFJavaServer Faces)、Web程序的国际化和本地化;

2.         Web服务:包含了用于开发Web服务的API,如JAX-WSJava API for XML-base Web Services,基本Web服务技术)、JAXBJava API for XML BindingXML组件技术)、STAXStreaming API for XMLXML流处理技术)、SAAJSOAP with Attachments API for JavaSOAP附件技术)、JAXRJava API for XML RegistriesXML注册技术);

3.         企业开发(EJB)技术:用于企业开发企业应用中的业务逻辑,如会话Bean、消息驱动Bean

4.         持久化技术:包括Java持久化API,用于在JavaEE程序中访问数据库,如:持久化APIWeb层持久化、EJB层持久化、持久化查询语言(QL);

5.         平台服务:包含可用于所有JavaEE5组件的服务技术,如事务处理、资源连接、安全、消息服务、连接器架构等。

 

图表 1 学习图径

在熟悉了相关内容后,你可能希望进行一些实战训练。本指南提供了两个完整的应用实例:

1.         Coffee Break:使用了Web程序开发和Web服务开发技术;

2.         Duke’s Bank:使用了Web程序开发、EJB、与持久化技术。

最后,附录中包含的Java编码表有助于学习Java EE 5的开发。

 

关于实例

以下内容讲述了如何安装、创建和运行实例。

软件环境

1.         指南安装包,如果你在线阅读本文档,你需要下载相应的安装内容进行安装,在安装完成后,代码将位于<安装目录>/javaeetutorial5/examples/目录及其子目录下;

2.         程序服务器,Sun公司的Java System Application Server Platform Edition 9是创建和运行本指南例子的必备环境,以及J2SE5.0 SDK。可以从http://java.sun.com/javaee/downloads/index.html中下载;安装时尽量选择”Don’t Prompt for Admin User Name”选项,及使用8080作为服务运行端口,并勾选”Add Bin Directory to PATH”选项;

3.         NetBeans 5.5:这是一个免费、开源的Java集成开发环境,支持JavaEE5的开发、部署,包括企业级开发,下载地址是:http://www.netbeans.org/downloads/index.html

4.         Apache Ant:一款基于Java技术的发布工具,用于创建、打包和部署程序;

5.         注册服务:在学习第19章节需要一个注册服务器;

编译示例程序

指南中各章节提供的示例可以使用NetBeans 5.5Ant中的任何一个进行编译。

NetBeans 5.5中编译示例

为了运行示例程序,你需要在NetBeans 5.5中注册你的程序服务器,如以下步骤:

1.    选择Tools->Server Manager打开服务管理对话框;

2.    点击Add Server

3.    选择Sun Java System Application Server,并点击下一步;

4.    输入安装程序服务器的位置;

5.    选择Register Local Default Domain,并点击下一步;

6.    输入在安装服务器时指定的管理员用户名和密码;

7.    点击完成。

使用Ant命令行编译示例程序

Build properties common to all the examples are specified in the build.properties file in the <INSTALL>/javaeetutorial5/examples/bp-project/ directory. You must create this file before you can run the examples. We've included a sample file, build.properties.sample, that you should rename to build.properties and edit to reflect your environment. The tutorial examples use the Java BluePrints (http://java.sun.com/reference/blueprints/) build system and application layout structure.

To run the Ant scripts, you must set common build properties in the file <INSTALL>/javaeetutorial5/examples/bp-project/build.properties as follows:

Set the javaee.home property to the location of your Application Server installation. The build process uses the javaee.home property to include the libraries in <JAVAEE_HOME>/lib/ in the classpath. All examples that run on the Application Server include the Java EE library archive--<JAVAEE_HOME>/lib/javaee.jar--in the build classpath. Some examples use additional libraries in <JAVAEE_HOME>/lib/; the required libraries are enumerated in the individual technology chapters. <JAVAEE_HOME> refers to the directory where you have installed the Application Server.

--------------------------------------------------------------------------------

Note: On Windows, you must escape any backslashes in the javaee.home property with another backslash or use forward slashes as a path separator. So, if your Application Server installation is C:/Sun/AppServer, you must set javaee.home as follows:

javaee.home = C://Sun//AppServer

or

javaee.home=C:/Sun/AppServer

--------------------------------------------------------------------------------

Set the javaee.tutorial.home property to the location of your tutorial. This property is used for Ant deployment and undeployment.

For example, on UNIX:

javaee.tutorial.home=/home/username/javaeetutorial5

On Windows:

javaee.tutorial.home=C:/javaeetutorial5

Do not install the tutorial to a location with spaces in the path.

If you did not use the default value (admin) for the admin user, set the admin.user property to the value you specified when you installed the Application Server.

If you did not use port 8080, set the domain.resources.port property to the value specified when you installed the Application Server.

Set the admin user's password in the admin-password.txt file in the <INSTALL>/javaeetutorial5/examples/common/ directory to the value you specified when you installed the Application Server. The format of this file is AS_ADMIN_PASSWORD=password. For example:

AS_ADMIN_PASSWORD=mypassword

示例程序结构

每个示例的结构基本如下:

l  build.xml: Ant 编译配置文件;

l  src/java: Java源代码文件;

l  src/conf: 模块的配置文件,以及除Web程序以外的部分;

l  web: 包含JSPHTML页面、样式表文件、标签文件和图像等;

l  web/WEB-INF: Web程序的配置文件;

l  nbproject: NetBeans的项目文件。

对于多外项目的目录中,包括以下名称部分:

l  <EXAMPLE_NAME>-app-client: 程序客户端;

l  <EXAMPLE_NAME>-ejb: 企业bean Jar文件;

l  <EXAMPLE_NAME>-war: Web程序。