Jan 18, 2008

J2EE

J2EE

因业务需要,“中科永联”正式更名为“中程在线”,欢迎大家浏览新网站“中程在线信息产业培训网

中科永联高级技术培训中心(www.itisedu.com

J2EE(Java 2 Enterprise Edition)是建立在Java 2平台上的企业级应用的解决方案。J2EE技术的基础便是Java 2平台,不但有J2SE平台的所有功能,同时还提供了对EJBServlet,JSP,XML等技术的全面支持,其最终目标是成为一个支持企业级应用开发的体系结构,简化企业解决方案的开发,部署和管理等复杂问题。事实上,J2EE已经成为企业级开发的工业标准和首选平台。

  J2EE并非一个产品,而是一系列的标准。市场上可以看到很多实现了J2EE的产品,如BEA WebLogic,IBM WebSphere以及开源JBoss等等。

J2EE,是sun公司提出的一个标准,符合这个标准的产品叫"实现";其中你下载的sun公司的j2ee开发包中就有一个这样的"实现",而 jboss,weblogic,websphere都是j2ee标准的一个"实现"。由于jboss,weblogic,websphere自身带有 j2ee的api,所以可以不使用sun的j2ee实现。

一. J2EE的概念

目前,Java 2平台有3个版本,它们是适用于小型设备和智能卡的Java 2平台Micro版(Java 2 Platform Micro Edition,J2ME)、适用于桌面系统的Java 2平台标准版(Java 2 Platform Standard Edition,J2SE)、适用于创建服务器应用程序和服务的Java2平台企业版(Java 2 Platform Enterprise Edition,J2EE)。

J2EE是一种利用Java 2平台来简化企业解决方案的开发、部署和管理相关的复杂问题的体系结构。J2EE技术的基础就是核心Java平台或Java 2平台的标准版,J2EE不仅巩固了标准版中的许多优点,例如"编写一次、随处运行"的特性、方便存取数据库JDBC API、CORBA技术以及能够在Internet应用中保护数据的安全模式等等,同时还提供了对 EJB(Enterprise JavaBeans)、Java Servlets API、JSP(Java Server Pages)以及XML技术的全面支持。其最终目的就是成为一个能够使企业开发者大幅缩短投放市场时间的体系结构。

J2EE体系结构提供中间层集成框架用来满足无需太多费用而又需要高可用性、高可靠性以及可扩展性的应用的需求。通过提供统一的开发平台,J2EE降低了开发多层应用的费用和复杂性,同时提供对现有应用程序集成强有力支持,完全支持Enterprise JavaBeans,有良好的向导支持打包和部署应用,添加目录支持,增强了安全机制,提高了性能。

二. J2EE的优势

J2EE为搭建具有可伸缩性、灵活性、易维护性的商务系统提供了良好的机制:
保留现存的IT资产: 由于企业必须适应新的商业需求,利用已有的企业信息系统方面的投资,而不是重新制定全盘方案就变得很重要。这样,一个以渐进的(而不是激进的,全盘否定的)方式建立在已有系统之上的服务器端平台机制是公司所需求的。J2EE架构可 以充分利用用户原有的投资,如一些公司使用的BEA Tuxedo、IBM CICS, IBM Encina,、Inprise VisiBroker 以及Netscape Application Server。这之所以成为可能是因为J2EE拥有广泛的业界支持和一些重要的'企业计算'领域供应商的参与。每一个供应商都对现有的客户提供了不用废弃 已有投资,进入可移植的J2EE领域的升级途径。由于基于J2EE平台的产品几乎能够在任何操作系统和硬件配置上运行,现有的操作系统和硬件也能被保留使用。

高效的开发: J2EE允许公司把一些通用的、很繁琐的服务端任务交给中间件供应商去完成。这样开发人员可以集中精力在如何创建商业逻辑上,相应地缩短了开发时间。高级中间件供应商提供以下这些复杂的中间件服务:

状态管理服务 -- 让开发人员写更少的代码,不用关心如何管理状态,这样能够更快地完成程序开发。
持续性服务 -- 让开发人员不用对数据访问逻辑进行编码就能编写应用程序,能生成更轻巧,与数据库无关的应用程序,这种应用程序更易于开发与维护。
分布式共享数据对象CACHE服务 -- 让开发人员编制高性能的系统,极大提高整体部署的伸缩性。
支持异构环境: J2EE能够开发部署在异构环境中的可移植程序。基于J2EE的应用程序不依赖任何特定操作系统、中间件、硬件。因此设计合理的基于J2EE的程序只需开 发一次就可部署到各种平台。这在典型的异构企业计算环境中是十分关键的。J2EE标准也允许客户订购与J2EE兼容的第三方的现成的组件,把他们部署到异构环境中,节省了由自己制订整个方案所需的费用。
可伸缩性: 企业必须要选择一种服务器端平台,这种平台应能提供极佳的可伸缩性去满足那些在他们系统上进行商业运作的大批新客户。基于J2EE平台的应用程序可被部署 到各种操作系统上。例如可被部署到高端UNIX与大型机系统,这种系统单机可支持64至256个处理器。(这是NT服务器所望尘莫及的)J2EE领域的供 应商提供了更为广泛的负载平衡策略。能消除系统中的瓶颈,允许多台服务器集成部署。这种部署可达数千个处理器,实现可高度伸缩的系统,满足未来商业应用的 需要。
稳定的可用性: 一个服务器端平台必须能全天候运转以满足公司客户、合作伙伴的需要。因为INTERNET是全球化的、无处不在的,即使在夜间按计划停机也可能造成严重损 失。若是意外停机,那会有灾难性后果。J2EE部署到可靠的操作环境中,他们支持长期的可用性。一些J2EE部署在WINDOWS环境中,客户也可选择健 壮性能更好的操作系统如Sun Solaris、IBM OS/390。最健壮的操作系统可达到99.999%的可用性或每年只需5分钟停机时间。这是实时性很强商业系统理想的选择。

三. J2EE 的四层模型

J2EE使用多层的分布式应用模型,应用逻辑按功能划分为组件,各个应用组件根据他们所在的层分布在不同的机器上。事实上,sun设计J2EE的初衷正是为了解决两层模式(client/server)的弊端,在传统模式中,客户端担 当了过多的角色而显得臃肿,在这种模式中,第一次部署的时候比较容易,但难于升级或改进,可伸展性也不理想,而且经常基于某种专有的协议――通常是某种数 据库协议。它使得重用业务逻辑和界面逻辑非常困难。现在J2EE 的多层企业级应用模型将两层化模型中的不同层面切分成许多层。一个多层化应用能够为不同的每种服务提供一个独立的层,以下是 J2EE 典型的四层结构:

运行在客户端机器上的客户层组件
运行在J2EE服务器上的Web层组件
运行在J2EE服务器上的业务逻辑层组件
运行在EIS服务器上的企业信息系统(Enterprise information system)层软件

J2EE应用程序组件
J2EE应用程序是由组件构成的.J2EE组件是具有独立功能的软件单元,它们通过相关的文件组装成J2EE应用程序,并与其他组件交互。J2EE说明书中定义了以下的J2EE组件:
应用客户端程序和applets是客户层组件.
Java Servlet和JavaServer Pages(JSP)是web层组件.
Enterprise JavaBeans(EJB)是业务层组件.

客户层组件
J2EE应用程序可以是基于web方式的,也可以是基于传统方式的.
web 层组件J2EE web层组件可以是JSP 页面或Servlets.按照J2EE规范,静态的HTML页面和Applets不算是web层组件。

正如下图所示的客户层那样,web层可能包含某些 JavaBean 对象来处理用户输入,并把
输入发送给运行在业务层上的enterprise bean 来进行处理。

业务层组件
业务层代码的逻辑用来满足银行,零售,金融等特殊商务领域的需要,由运行在业务层上的enterprise bean 进行处理. 下图表明了一个enterprise bean 是如何从客户端程序接收数据,进行处理(如果必要的话), 并发送到EIS 层储存的,这个过程也可以逆向进行。

有三种企业级的bean: 会话(session) beans, 实体(entity) beans, 和 消息驱 动(message-driven) beans. 会话bean 表示与客户端程序的临时交互. 当客户端程序执行完后, 会话bean 和相关数据就会消失. 相反, 实体bean 表示数据库的表中一行永久的记录. 当客户端程序中止或服务器关闭时, 就会有潜在的服务保证实体bean 的数据得以保存.消息驱动 bean 结合了会话bean 和 JMS的消息监听器的特性, 允许一个业务层组件异步接收JMS 消息.

企业信息系统层
企业信息系统层处理企业信息系统软件包括企业基础建设系统例如企业资源计划 (ERP), 大型机事务处理, 数据库系统,和其它的遗留信息系统. 例如,J2EE 应用组件可能为了数据库连接需要访问企业信息系统

我们就J2EE的各种组件、服务和API,进行更加详细的阐述,看看在开发不同类型的企业级应用时,根据各自需求和目标的不同,应当如何灵活使用并组合不同的组件和服务。

· Servlet

Servlet是Java平台上的CGI技术。Servlet在服务器端运行,动态地生成Web页面。与传统的CGI和许多其它类似CGI的技术相比, Java Servlet具有更高的效率并更容易使用。对于Servlet,重复的请求不会导致同一程序的多次转载,它是依靠线程的方式来支持并发访问的。

· JSP

JSP(Java Server Page)是一种实现普通静态HTML和动态页面输出混合编码的技术。从这一点来看,非常类似Microsoft ASP、PHP等 技术。借助形式上的内容和外观表现的分离,Web页面制作的任务可以比较方便地划分给页面设计人员和程序员,并方便地通过JSP来合成。在运行时态, JSP将会被首先转换成Servlet,并以Servlet的形态编译运行,因此它的效率和功能与Servlet相比没有差别,一样具有很高的效率。

· EJB

EJB定义了一组可重用的组件:Enterprise Beans。开发人员可以利用这些组件,像搭积木一样建立分布式应用。在装配组件时,所有的Enterprise Beans都需要配置到EJB服务器(一般的Weblogic、WebSphere等J2EE应用服务器都 是EJB服务器)中。EJB服务器作为容器和低层平台的桥梁管理着EJB容器,并向该容器提供访问系统服务的能力。所有的EJB实例都运行在EJB容器 中。EJB容器提供了系统级的服务,控制了EJB的生命周期。EJB容器为它的开发人员代管了诸如安全性、远程连接、生命周期管理及事务管理等技术环节, 简化了商业逻辑的开发。EJB中定义了三种Enterprise Beans:

◆ Session Beans

◆ Entity Beans

◆ Message-driven Beans

· JDBC

JDBC(Java Database Connectivity,Java数据库连接)API是一个标准SQL(Structured Query Language, 结构化查询语言)数据库访问接口,它使数据库开发人员能够用标准Java API编写数据库应用程序。JDBC API主要用来连接数据库和直接调用SQL命令执行各种SQL语句。利用JDBC API可以执行一般的SQL语句、动态SQL语句及带IN和OUT参数的存储过程。Java中的JDBC相当与Microsoft平台中的ODBC(Open Database Connectivity)。

· JMS

JMS(Java Message ServiceJava消息服务) 是一组Java应用接口,它提供创建、发送、接收、读取消息的服务。JMS API定义了一组公共的应用程序接口和相应语法,使得Java应用能够和各种消息中间件进行通信,这些消息中间件包括IBM MQ-Series、Microsoft MSMQ及纯Java的SonicMQ。通过使用JMS API,开发人员无需掌握不同消息产品的使用方法,也可以使用统一的JMS API来操纵各种消息中间件。通过使用JMS,能够最大限度地提升消息应用的可移植性。 JMS既支持点对点的消息通信,也支持发布/订阅式的消息通信。

· JNDI

由于J2EE应用程序组件一般分布在不同的机器上,所以需要一种机制以便于组件客户使用者查找和引用组件及资源。在J2EE体系中,使用JNDI (Java Naming and Directory Interface)定位各种对象,这些对象包括EJB、数据库驱动、JDBC数据源及消息连接等。JNDI API为应用程序提供了一个统一的接口来完成标准的目录操作,如通过对象属性来查找和定位该对象。由于JNDI是独立于目录协议的,应用还可以使用 JNDI访问各种特定的目录服务,如LDAP、NDS和DNS等。

· JTA

JTA(Java Transaction API)提供了J2EE中处理事务的标准接口,它支持事务的开始、回滚和提交。同时在一般的J2EE平台上,总提供一个JTS(Java Transaction Service)作为标准的事务处理服务,开发人员可以使用JTA来使用JTS。

· JCA

JCA(J2EE Connector Architecture)是J2EE体系架构的一部分,为开发人员提供了一套连接各种企业信息系统(EIS,包括ERP、SCM、CRM等)的体系架构,对于EIS开发商而言,它们只需要开发一套基于JCA的EIS连接适配器,开发人员就能够在任何的J2EE应用服务器中连接并使用它。基于JCA的连接适配器的实现,需要涉及J2EE中的事务管理、安全管理及连接管理等服务组件。

· JMX

JMX(Java Management Extensions)的前身是JMAPI。JMX致力于解决分布式系统管理的问题。JMX是一种应用编程接口、 可扩展对象和方法的集合体,可以跨越各种异构操作系统平台、系统体系结构和网络传输协议,开发无缝集成的面向系统、网络和服务的管理应用。JMX是一个完 整的网络管理应用程序开发环境,它同时提供了厂商需要收集的完整的特性清单、可生成资源清单表格、图形化的用户接口;访问SNMP的网络API;主机间远程过程调用;数据库访问方法等。

· JAAS

JAAS(Java Authentication and Authorization Service)实现了一个Java版本的标准Pluggable Authentication Module(PAM)的框架。JAAS可用来进行用户身份的鉴定,从而能够可靠并安全地确定谁在执行Java代码。同时JAAS还能通过对用户进行授 权,实现基于用户的访问控制。

· JACC

JACC(Java Authorization Service Provider Contract for Containers)在J2EE应用服务器和特定的授权认证服务器之间定义了一个连接的协约,以便将各种授权认证服务器插入到J2EE产品中去。

· JAX-RPC

通过使用JAX-RPC(Java API for XML-based RPC),已有的Java类或Java应用都能够被重新包装,并以Web Services的形式发布。JAX-RPC提供了将RPC参数(in/out)编码和解码的API,使开发人员可以方便地使用SOAP消息来完成RPC 调用。同样,对于那些使用EJB(Enterprise JavaBeans)的商业应用而言,同样可以使用JAX-RPC来包装成Web服务,而这个Web Servoce的WSDL界面是与原先的EJB的方法是对应一致的。JAX-RPC为用户包装了Web服务的部署和实现,对Web服务的开发人员而言, SOAP/WSDL变得透明,这有利于加速Web服务的开发周期。

· JAXR

JAXR(Java API for XML Registries)提供了与多种类型注册服务进行交互的API。JAXR运行客户端访问与JAXR规范相兼容的Web Servcices,这里的Web Services即为注册服务。一般来说,注册服务总是以Web Services的形式运行的。JAXR支持三种注册服务类型:JAXR Pluggable Provider、Registry-specific JAXR Provider、JAXR Bridge Provider(支持UDDI Registry和ebXML Registry/Repository等)。

· SAAJ

SAAJ(SOAP with Attachemnts API for Java)是JAX-RPC的一个增强,为进行低层次的SOAP消息操纵提供了支持。

四. J2EE 的结构

这种基于组件,具有平台无关性的J2EE 结构使得J2EE 程序的编写十分简单,因为业务逻辑被封装成可复用的组件,并且J2EE 服务器以容器的形式为所有的组件类型提供后台服务. 因为你不用自己开发这种服务, 所以你可以集中精力解决手头的业务问题.

容器和服务

容器设置定制了J2EE服务器所提供得内在支持,包括安全,事务管理,JNDI(Java Naming and Directory Interface)寻址,远程连接等服务,以下列出最重要的几种服务:

J2EE安全(Security)模型可以让你配置 web 组件或enterprise bean ,这样只有被授权的用户才能访问系统资源. 每一客户属于一个特别的角色,而每个角色只允许激活特定的方法。你应在enterprise bean的布置描述中声明角色和可被激活的方法。由于这种声明性的方法,你不必编写加强安全性的规则。

J2EE 事务管理(Transaction Management)模型让你指定组成一个事务中所有方法间的关系,这样一个事务中的所有方法被当成一个单一的单元. 当客户端激活一个enterprise bean中的方法,容器介入一管理事务。因有容器管理事务,在enterprise bean中不必对事务的边界进行编码。要求控制分布式事务的代码会非常复杂。你只需在布置描述文件中声明enterprise bean的事务属性,而不用编写并调试复杂的代码。容器将读此文件并为你处理此enterprise bean的事务。

JNDI 寻址(JNDI Lookup)服务向企业内的多重名字和目录服务提供了一个统一的接口,这样应用程序组件可以访问名字和目录服务.

J2EE远程连接(Remote Client Connectivity)模型管理客户端和enterprise bean间的低层交互. 当一个enterprise bean创建后, 一个客户端可以调用它的方法就象它和客户端位于同一虚拟机上一样.

生存周期管理(Life Cycle Management)模型管理enterprise bean的创建和移除,一个enterprise bean在其生存周期中将会历经几种状态。容器创建enterprise bean,并在可用实例池与活动状态中移动他,而最终将其从容器中移除。即使可以调用enterprisebean的create及remove方法,容 器也将会在后台执行这些任务。

五、企业级应用示例

下面我们通过假设一个企业应用的J2EE实现,来了解各种组件和服务的应用。假设应用对象是计算机产品的生产商/零售商的销售系统,这个销售系统能够通过自己的网站发布产品信息,同时也能将产品目录传送给计算机产品交易市场。销售系统能够在线接受订单(来自自己的Web网站或者来自计算机产品交易市场),并随后转入内部企业管理系统进行相关的后续处理。

参见图1,这个企业应用可以这种方式架构。该企业应用的核心是产品目录管理和产品定购管理这两个业务逻辑,使用EJB加以实现,并部署在EJB容器中。由于产品目录和定购信息都需要持久化,因此使用JDBC连接数据库,并使用JTA来完成数据库存取事务。


图1 J2EE应用示例

然后使用JSP/Servlet来实现应用的Web表现:在线产品目录浏览和在线定购。为了将产品目录发送给特定的交易市场,使用JMS实现异步的基于消 息的产品目录传输。为了使得更多的其它外部交易市场能够集成产品目录和定购业务,需要使用Web Services技术包装商业逻辑的实现。由于产品定购管理需要由公司内部雇员进行处理,因此需要集成公司内部的用户系统和访问控制服务以方便雇员的使 用,使用JACC集成内部的访问控制服务,使用JNDI集成内部的用户目录,并使用JAAS进行访问控制。由于产品订购事务会触发后续的企业ERP系统的 相关操作(包括仓储、财务、生产等),需要使用JCA连接企业ERP。

最后为了将这个应用纳入到企业整体的系统管理体系中去,使用Application Client架构了一个管理客户端(与其它企业应用管理应用部署在一台机器上),并通过JMX管理这个企业应用。

初学者如何开发出一个高质量的J2EE系统

初学者如何开发出一个高质量的J2EE系统

板桥里人 http://www.jdon.com 2005/06/20


  J2EE学习者越来越多,J2EE本身技术不断在发展,涌现出各种概念,本文章试图从一种容易理解的角度对这些概念向初学者进行解释,以便掌握学习J2EE学习方向。

  首先我们需要知道Java和J2EE是两个不同概念,Java不只是指一种语言,已经代表与微软不同的另外一个巨大阵营,所以Java有时是指一种软件系统的流派,当然目前主要是.NET和Java两大主流体系。

  J2EE可以说指Java在数据库信息系统上实现,数据库信息系统从早期的dBase、到Delphi/VB等C/S结构,发展到B/S(Browser浏览器/Server服务器)结构,而J2EE主要是指B/S结构的实现。

  J2EE又是一种框架和标准,框架类似API、库的概念,但是要超出它们。如果需要详细了解框架,可先从设计模式开始学习。

  J2EE是一个虚的大的概念,J2EE标准主要有三种子技术标准:WEB技术、EJB技术和JMS,谈到J2EE应该说最终要落实到这三个子概念上。

  这三种技术的每个技术在应用时都涉及两个部分:容器部分和应用部分,Web容器也是指Jsp/Servlet容器,你如果要开发一个Web应用,无论是编译或运行,都必须要有Jsp/Servlet库或API支持(除了JDK/J2SE以外)。

  Web技术中除了Jsp/Servlet技术外,还需要JavaBeans或Java Class实现一些功能或者包装携带数据,所以Web技术最初裸体简称为Jsp/Servlet+JavaBeans系统。

  谈到JavaBeans技术,就涉及到组件构件技术(component),这是Java的核心基础部分,很多软件设计概念(设计模式)都是通过JavaBeans实现的。

  JavaBeans不属于J2EE概念范畴中,如果一个JavaBeans对象被Web技术(也就是Jsp/Servlet)调用,那么JavaBeans就运行在J2EE的Web容器中;如果它被EJB调用,它就运行在EJB容器中。

  EJB(企业JavaBeans)是普通JavaBeans的一种提升和规范,因为企业信息系统开发中需要一个可伸缩的性能和事务、安全机制,这样能保证企业系统平滑发展,而不是发展到一种规模重新更换一套软件系统。

   至此,JavaBeans组件发展到EJB后,并不是说以前的那种JavaBeans形式就消失了,这就自然形成了两种JavaBeans技术:EJB 和POJO,POJO完全不同于EJB概念,指的是普通JavaBeans,而且这个JavaBeans不依附某种框架,或者干脆可以说:这个 JavaBeans是你为这个应用程序单独开发创建的。

  J2EE应用系统开发工具有很多:如 JBuilder、Eclipse等,这些IDE首先是Java开发工具,也就是说,它们首要基本功能是可以开发出JavaBeans或Java class,但是如果要开发出J2EE系统,就要落实到要么是Web技术或EJB技术,那么就有可能要一些专门模块功能(如eclipse需要 lomboz插件),最重要的是,因为J2EE系统区分为容器和应用两个部分,所以,在任何开发工具中开发J2EE都需要指定J2EE容器。

   J2EE容器分为WEB容器和EJB容器,Tomcat/Resin是Web容器;JBoss是EJB容器+Web容器等,其中Web容器直接使用 Tomcat实现的。所以你开发的Web应用程序可以在上面两种容器运行,而你开发的Web+EJB应用则只可以在JBoss服务器上运行,商业产品 Websphere/Weblogic等和JBoss属于同一种性质。

  J2EE容器也称为J2EE服务器,大部分时它们概念是一致的。

   如果你的J2EE应用系统的数据库连接是通过JNDI获得,也就是说是从容器中获得,那么你的J2EE应用系统基本与数据库无关,如果你在你的J2EE 应用系统耦合了数据库JDBC驱动的配置,那么你的J2EE应用系统就有数据库概念色彩,作为一个成熟需要推广的J2EE应用系统,不推荐和具体数据库耦 合,当然这其中如何保证J2EE应用系统运行性能又是体现你的设计水平了。

  衡量J2EE应用系统设计开发水平高低的标准就是:解耦性;你的应用系统各个功能是否能够彻底脱离?是否不相互依赖,也只有这样,才能体现可维护性、可拓展性的软件设计目标。

  为了达到这个目的,诞生各种框架概念,J2EE框架标准将一个系统划分为WEB和EJB主要部分,当然我们有时不是以这个具体技术区分,而是从设计上抽象为表现层、服务层和持久层,这三个层次从一个高度将J2EE分离开来,实现解耦目的。

  因此,我们实际编程中,也要将自己的功能向这三个层次上靠,做到大方向清楚,泾渭分明,但是没有技术上约束限制要做到这点是很不容易的,因此我们还是必须借助J2EE具体技术来实现,这时,你可以使用EJB规范实现服务层和持久层,Web技术实现表现层;

  EJB为什么能将服务层从Jsp/Servlet手中分离出来,因为它对JavaBeans编码有强制的约束,现在有一种对JavaBeans弱约束,使用Ioc模式实现的(当然EJB 3.0也采取这种方式),在Ioc模式诞生前,一般都是通过工厂模式来对JavaBeans约束,形成一个服务层,这也是是Jive这样开源论坛设计原理之一。

  由此,将服务层从表现层中分离出来目前有两种可选架构选择:管理普通JavaBeans(POJO)框架(如Spring、JdonFramework)以及管理EJB的EJB框架,因为EJB不只是框架,还是标准,而标准可以扩展发展,所以,这两种区别将来是可能模糊,被纳入同一个标准了。 但是,个人认为:标准制定是为某个目的服务的,总要牺牲一些换取另外一些,所以,这两种架构会长时间并存。

   这两种架构分歧也曾经诞生一个新名词:完全POJO的系统也称为轻量级系统(lightweight),其实这个名词本身就没有一个严格定义,更多是一 个吸引人的招牌,轻量是指容易学习容易使用吗?按照这个定义,其实轻量Spring等系统并不容易学习;而且EJB 3.0(依然叫EJB)以后的系统是否可称为轻量级了呢?

  前面谈了服务层框架,使用服务层框 架可以将JavaBeans从Jsp/Servlet中分离出来,而使用表现层框架则可以将Jsp中剩余的JavaBeans完全分离,这部分 JavaBeans主要负责显示相关,一般是通过标签库(taglib)实现,不同框架有不同自己的标签库,Struts是应用比较广泛的一种表现层框 架。

  这样,表现层和服务层的分离是通过两种框架达到目的,剩余的就是持久层框架了,通过持久层的框架将数据库存储从服务层中分离出来是其目的,持久层框架有两种方向:直接自己编写JDBC等SQL语句(如iBatis);使用O/R Mapping技术实现的Hibernate和JDO技术;当然还有EJB中的实体Bean技术。

  持久层框架目前呈现百花齐放,各有优缺点的现状,所以正如表现层框架一样,目前没有一个框架被指定为标准框架,当然,表现层框架现在又出来了一个JSF,它代表的页面组件概念是一个新的发展方向,但是复杂的实现让人有些忘而却步。

   在所有这些J2EE技术中,虽然SUN公司发挥了很大的作用,不过总体来说:网络上有这样一个评价:SUN的理论天下无敌;SUN的产品用起来撞墙;对 于初学者,特别是那些试图通过或已经通过SUN认证的初学者,赶快摆脱SUN的阴影,立即开溜,使用开源领域的产品来实现自己的应用系统。

  最后,你的J2EE应用系统如果采取上面提到的表现层、服务层和持久层的框架实现,基本你也可以在无需深刻掌握设计模式的情况下开发出一个高质量的应用系统了。

  还要注意的是: 开发出一个高质量的J2EE系统还需要正确的业务需求理解,那么域建模提供了一种比较切实可行的正确理解业务需求的方法,相关详细知识可从UML角度结合理解。

   当然,如果你想设计自己的行业框架,那么第一步从设计模式开始吧,因为设计模式提供你一个实现JavaBeans或类之间解耦参考实现方法,当你学会了 系统基本单元JavaBean或类之间解耦时,那么系统模块之间的解耦你就可能掌握,进而你就可以实现行业框架的提炼了,这又是另外一个发展方向了。

  以上理念可以总结为一句话:
J2EE开发三件宝: Domain Model(域建模)、patterns(模式)和framework(框架)。

  推荐一套高质量的J2EE开源系统: JPestore
  
  如果初学者没有理解,欢迎继续讨论,大胆提出你心中的疑问。

参考文章:Java企业系统架构选择考量

Jdon Framework的服务调用命令模式实现

Dec 18, 2007

EMCAS Command

SourceForge Logo
Emacs Commands List

C = Control
M = Meta = Alt|Esc

Basics
C-x C-f "find" file i.e. open/create a file in buffer
C-x C-s save the file
C-x C-w write the text to an alternate name
C-x C-v find alternate file
C-x i insert file at cursor position
C-x b create/switch buffers
C-x C-b show buffer list
C-x k kill buffer
C-z suspend emacs
C-X C-c close down emacs

Basic movement
C-f forward char
C-b backward char
C-p previous line
C-n next line
M-f forward one word
M-b backward one word
C-a beginning of line
C-e end of line
C-v one page up
M-v scroll down one page
M-< beginning of text
M-> end of text

Editing
M-n repeat the following command n times
C-u repeat the following command 4 times
C-u n repeat n times
C-d delete a char
M-d delete word
M-Del delete word backwards
C-k kill line

C-Space Set beginning mark (for region marking for example)
C-W "kill" (delete) the marked region region
M-W copy the marked region
C-y "yank" (paste) the copied/killed region/line
M-y yank earlier text (cycle through kill buffer)
C-x C-x exchange cursor and mark

C-t transpose two chars
M-t transpose two words
C-x C-t transpose lines
M-u make letters uppercase in word from cursor position to end
M-c simply make first letter in word uppercase
M-l opposite to M-u

Important
C-g quit the running/entered command
C-x u undo previous action
M-x revert-buffer RETURN (insert like this) undo all changes since last save
M-x recover-file RETURN Recover text from an autosave-file
M-x recover-session RETURN if you edited several files

Online-Help
C-h c which command does this keystroke invoke
C-h k which command does this keystroke invoke and what does it do?
C-h l what were my last 100 typed keys
C-h w what key-combo does this command have?
C-h f what does this function do
C-h v what's this variable and what is it's value
C-h b show all keycommands for this buffer
C-h t start the emacs tutorial
C-h i start the info reader
C-h C-k start up info reader and go to a certain key-combo point
C-h F show the emacs FAQ
C-h p show infos about the Elisp package on this machine

Search/Replace
C-s Search forward
C-r search backward
C-g return to where search started (if you are still in search mode)
M-% query replace

Space or y replace this occurence
Del or n don't replace
. only replace this and exit (replace)
, replace and pause (resume with Space or y)
! replace all following occurences
^ back to previous match
RETURN or q quit replace


Search/Replace with regular expressions
Characters to use in regular expressions:
^ beginning of line
$ end of line
. single char
.* group or null of chars
\< beginning of a word
\> end of a word
[] every char inside the backets (for example [a-z] means every small letter)

M C-s RETURN search for regular expression forward
M C-r RETURN search for regular expression backward
M C-s incremental search
C-s repeat incremental search
M C-r incremental search backwards
C-r repeat backwards
M-x query-replace-regexp search and replace

Window-Commands
C-x 2 split window vertically
C-x o change to other window
C-x 0 delete window
C-x 1 close all windows except the one the cursors in
C-x ^ enlarge window
M-x shrink-window command says it ;-)
M C-v scroll other window
C-x 4 f find file in other window
C-x 4 o change to other window
C-x 4 0 kill buffer and window
C-x 5 2 make new frame
C-x 5 f find file in other frame
C-x 5 o change to other frame
C-x 5 0 close this frame

Bookmark commands
C-x r m set a bookmark at current cursor pos
C-x r b jump to bookmark
M-x bookmark-rename says it
M-x bookmark-delete "
M-x bookmark-save "
C-x r l list bookmarks

d mark bookmark for deletion
r rename bookmark
s save all listed bookmarks
f show bookmark the cursor is over
m mark bookmarks to be shown in multiple window
v show marked bookmarks (or the one the cursor is over)
t toggle listing of the corresponding paths
w " path to this file
x delete marked bookmarks
Del ?
q quit bookmark list


M-x bookmark-write write all bookmarks in given file
M-x bookmark-load load bookmark from given file

Shell
M-x shell starts shell modus
C-c C-c same as C-c under unix (stop running job)
C-d delete char forward
C-c C-d Send EOF
C-c C-z suspend job (C-z under unix)
M-p show previous commands

DIRectory EDitor (dired)
C-x d start up dired
C (large C) copy
d mark for erase
D delete right away
e or f open file or directory
g reread directory structure from file
G change group permissions (chgrp)
k delete line from listing on screen (don't actually delete)
m mark with *
n move to next line
o open file in other window and go there
C-o open file in other window but don't change there
P print file
q quit dired
Q do query-replace in marked files
R rename file
u remove mark
v view file content
x delete files marked with D
z compress file
M-Del remove all marks (whatever kind)
~ mark backup files (name~ files) for deletion
# mark auto-save files (#name#) for deletion
*/ mark directory with * (C-u * removes that mark again)
= compare this file with marked file
M-= compare this file with it's backup file
! apply shell command to this file
M-} change to the next file marked with * od D
M-{ " previous "
% d mark files described through regular expression for deletion
% m " (with *)
+ create directory
> changed to next dir
< change to previous dir
s toggle between sorting by name or date

Maybe into this category also fits this command:
M-x speedbar starts up a separate window with a directory view

Telnet
M-x telnet starts up telnet-modus
C-d either delete char or send EOF
C-c C-c stop running job (similar to C-c under unix)
C-c C-d send EOF
C-c C-o clear output of last command
C-c C-z suspend execution of command
C-c C-u kill line backwards
M-p recall previous command

Text
Works only in text mode
M-s center line
M-S center paragraph
M-x center-region name says

Macro-commands
C-x ( start macro definition
C-x ) end of macro definition
C-x e execute last definied macro
M-n C-x e execute last defined macro n times
M-x name-last-kbd-macro give name to macro (for saving)
M-x insert-keyboard-macro save named macro into file
M-x load-file load macro
M-x macroname execute macroname

Programming
M C-\ indent region between cursor and mark
M-m move to first (non-space) char in this line
M-^ attach this line to previous
M-; formatize and indent comment
C, C++ and Java Modes
M-a beginning of statement
M-e end of statement
M C-a beginning of function
M C-e end of function
C-c RETURN Set cursor to beginning of function and mark at the end
C-c C-q indent the whole function according to indention style
C-c C-a toggle modus in which after electric signs (like {}:';./*) emacs does the indention
C-c C-d toggle auto hungry mode in which emacs deletes groups of spaces with one del-press
C-c C-u go to beginning of this preprocessor statement
C-c C-c comment out marked area
More general (I guess)
M-x outline-minor-mode collapses function definitions in a file to a mere {...}
M-x show-subtree If you are in one of the collapsed functions, this un-collapses it
In order to achive some of the feats coming up now you have to run etags *.c *.h *.cpp (or what ever ending you source files have) in the source directory
M-. (Thats Meta dot) If you are in a function call, this will take you to it's definition
M-x tags-search ENTER Searches through all you etaged
M-, (Meta comma) jumps to the next occurence for tags-search
M-x tags-query-replace yum. This lets you replace some text in all the tagged files


GDB (Debugger)
M-x gdb starts up gdm in an extra window

Version Control
C-x v d show all registered files in this dir
C-x v = show diff between versions
C-x v u remove all changes since last checkin
C-x v ~ show certain version in different window
C-x v l print log
C-x v i mark file for version control add
C-x v h insert version control header into file
C-x v r check out named snapshot
C-x v s create named snapshot
C-x v a create changelog file in gnu-style

NEWS

8.1.2002: The first part comes here

Last update: 8.1.2002

Nov 18, 2007

www.advancedlinuxprogramming

http://www.advancedlinuxprogramming.com/listings/

Basic Emacs Editor Commands

Colorado State University

Basic Emacs Editor Commands



What is Emacs?

Emacs is another editor available in UNIX. Like vi, emacs is a screen editor. Unlike vi, emacs is not an insertion mode editor, meaning that any character typed in emacs is automatically inserted into the file, unless it includes a command prefix.

Commands in emacs are either control characters (hold down the <Ctrl> key while typing another character) or are prefixed by one of a set of reserved characters: <Esc> or <Ctrl>-X. The <Esc> key can be typed by itself (because it really is a character) and then followed by another character; the <Ctrl> key must be held down while the next character is being typed. The conventions for describing these characters (since it takes too long to type out the whole thing) are ESC means <Esc> and C- means <Ctrl>.

One other distinction between emacs and vi is that emacs allows you to edit several files at once. The window for emacs can be divided into several windows, each of which contains a view into a buffer. Each buffer typically corresponds to a different file. Many of the commands listed below are for reading files into new buffers and moving between buffers.

To use emacs on a file, type
        emacs filename
If the file named filename exists, then the first screen's worth of the file is displayed; if it doesn't exist, a help message is displayed.

The easiest way to learn emacs is to start it up and go through the on-line tutorial. To access the on-line tutorial, type
        ESC help-with-tutorial
immediately after you have started emacs. The tutorial directs you further in learning the basic commands. One notational point you should know is that the tutorial uses M- to mean ESC.

To give you a head start, the following table lists the basic commands you need to know to use emacs to edit a file. An asterisk (* or star) to the left of a command indicate it is one to learn immediately.


Help Commands

* C-h help-command: first character in lots of useful help commands
* C-h t help-with-tutorial: command to run the tutorial
C-h i information: describes most of the emacs commands in man style pages
C-h k describe-key: tells you what a particular key stroke does
* C-h a command-apropos: prompts for a string and
then searches for all emacs commands that contains that string
ESC ? also does command-apropos
* C-h ? help-for-help: describes how to use the help facilities

File Reading and Writing Commands

* C-x C-f find-file: first prompts for a filename and
then loads that file into a editor buffer of the same name
* C-x C-s save-buffer: saves the buffer into the associated filename
C-x C-w write-named-file: prompts for a new filename and writes the buffer into it

Cursor/Screen Movement Commands

Depending on the terminal, some of the cursor movement can be handled by the arrow keys.

* C-a move cursor to (at) beginning-of-line
C-e move cursor to end-of-line
* C-f move cursor forward one character
* C-b move cursor backward one character
* C-n move cursor to next line
* C-p move cursor to previous line
C-v scroll file forward by one screenful
ESC v scroll file backward by one screenful
* ESC < go to beginning-of-buffer
* ESC > go to end-of-buffer
ESC f move cursor forward one word
ESC b move cursor backward one word

Copy and Delete Commands

C-d delete-char: delete character under cursor
ESC d delete-word: delete from cursor to end of word immediately ahead of the cursor
* C-k kill-line: delete the rest of the current line
* C-@ set-mark-command: mark is used to indicate the beginning of an area of text to be yanked
* C-w kill-region: delete the area of text between the mark and the current cursor position
* C-y yank: insert at current cursor location whatever was most recently deleted
ESC w copy-region-as-kill: copy area between mark and cursor into kill-buffer
so that it can be yanked into someplace else

Search Commands

* C-s isearch-forward: prompts for text string and
then searches from the current cursor position forwards in the buffer
C-r isearch-backward: like isearch-forward,
but searches from the current cursor position to end of buffer for text string
ESC % query-replace: prompts for a search string and
a string with which to replace the search string

Window and Buffer Commands

C-x 0 zero-window: deletes current window
C-x 2 double-window: splits current window into two parts,
allowing you to edit at two different locations in the same file
or permitting you to view two different files at the same time
C-x b switch-to-buffer: display a different buffer on the screen
C-x o other-window: move the cursor to the other window
(assuming that you have two windows/buffers open at once
* C-x C-b list-buffers: lists those buffers currently loaded into emacs

Exiting Emacs, Fixing Mistakes and Other Important Stuff

* C-x C-c save-buffers-kill-emacs: when you are finished editing,
to save the edited but unsaved buffers
and to return you to the UNIX prompt
* C-g keyboard-quit: if while typing a command you make a mistake and want to stop,
this aborts a command in progress
C-u universal-argument: if you want to do a command several times,
type this command
followed by a number (for the number of times)
followed by the command you wish repeated
* C-x u undo: undoes the last command typed, in case you made a mistake
* ESC x execute-extended-command: prompts for the name of an emacs command;
allows you to execute a command
if you know roughly what it is called
but cannot remember the key strokes for it


Other Emacs Bindings

Emacs has many other useful commands. As you get more proficient at it, try listing the key bindings (ESC-x for describe-bindings) to find other commands. Also note that emacs has what is called escape-completion: as you type in commands or filenames, you can type a space at any time and emacs will either fill out the rest (if there is only one possible completion) or it will list the possible completions in a new window.

A Web page with a complete list of emacs bindings is also available.



Comments:
Copyright &#169 1998: Colorado State University, CS Department. All rights reserved.

Emacs Command Summary

Emacs command summary, Thu Jul 25.

C-SP set-mark-command C-q quoted-insert
C-a beginning-of-line C-r isearch-backward
C-b backward-char C-s isearch-forward
C-c exit-recursive-edit C-t transpose-chars
C-d delete-char C-u universal-argument
C-e end-of-line C-v scroll-up
C-f forward-char C-w kill-region
C-h help-command C-x Control-X-prefix
TAB indent-for-tab-command C-y yank
LFD newline-and-indent C-z suspend-emacs
C-k kill-line ESC ESC-prefix
C-l recenter C-] abort-recursive-edit
RET newline C-_ undo
C-n next-line SPC .. ~ self-insert-command
C-o open-line DEL delete-backward-char
C-p previous-line

C-h v describe-variable C-h d describe-function
C-h w where-is C-h k describe-key
C-h t help-with-tutorial C-h c describe-key-briefly
C-h s describe-syntax C-h b describe-bindings
C-h n view-emacs-news C-h a command-apropos
C-h C-n view-emacs-news C-h C-d describe-distribution
C-h m describe-mode C-h C-c describe-copying
C-h l view-lossage C-h ? help-for-help
C-h i info C-h C-h help-for-help
C-h f describe-function

C-x C-a add-mode-abbrev C-x 5 split-window-horizontally
C-x C-b list-buffers C-x ; set-comment-column
C-x C-c save-buffers-kill-emacs C-x < scroll-left
C-x C-d list-directory C-x = what-cursor-position
C-x C-e eval-last-sexp C-x > scroll-right
C-x C-f find-file C-x [ backward-page
C-x C-h inverse-add-mode-abbrev C-x ] forward-page
C-x TAB indent-rigidly C-x ^ enlarge-window
C-x C-l downcase-region C-x ` next-error
C-x C-n set-goal-column C-x a append-to-buffer
C-x C-o delete-blank-lines C-x b switch-to-buffer
C-x C-p mark-page C-x d dired
C-x C-q toggle-read-only C-x e call-last-kbd-macro
C-x C-r find-file-read-only C-x f set-fill-column
C-x C-s save-buffer C-x g insert-register
C-x C-t transpose-lines C-x h mark-whole-buffer
C-x C-u upcase-region C-x i insert-file
C-x C-v find-alternate-file C-x j register-to-dot
C-x C-w write-file C-x k kill-buffer
C-x C-x exchange-dot-and-mark C-x l count-lines-page
C-x C-z suspend-emacs C-x m mail
C-x ESC repeat-complex-command C-x n narrow-to-region
C-x $ set-selective-display C-x o other-window
C-x ( start-kbd-macro C-x p narrow-to-page
C-x ) end-kbd-macro C-x q kbd-macro-query
C-x + add-global-abbrev C-x r copy-rectangle-to-register
C-x - inverse-add-global-abbrev C-x s save-some-buffers
C-x . set-fill-prefix C-x u advertised-undo
C-x / dot-to-register C-x w widen
C-x 0 delete-window C-x x copy-to-register
C-x 1 delete-other-windows C-x { shrink-window-horizontally
C-x 2 split-window-vertically C-x } enlarge-window-horizontally
C-x 4 ctl-x-4-prefix C-x DEL backward-kill-sentence

ESC C-SP mark-sexp ESC = count-lines-region
ESC C-a beginning-of-defun ESC > end-of-buffer
ESC C-b backward-sexp ESC @ mark-word
ESC C-c exit-recursive-edit ESC O ??
ESC C-d down-list ESC [ backward-paragraph
ESC C-e end-of-defun ESC delete-horizontal-space
ESC C-f forward-sexp ESC ] forward-paragraph
ESC C-h mark-defun ESC ^ delete-indentation
ESC LFD indent-new-comment-line ESC a backward-sentence
ESC C-k kill-sexp ESC b backward-word
ESC C-n forward-list ESC c capitalize-word
ESC C-o split-line ESC d kill-word
ESC C-p backward-list ESC e forward-sentence
ESC C-s isearch-forward-regexp ESC f forward-word
ESC C-t transpose-sexps ESC g fill-region
ESC C-u backward-up-list ESC h mark-paragraph
ESC C-v scroll-other-window ESC i tab-to-tab-stop
ESC C-w append-next-kill ESC j indent-new-comment-line
ESC ESC ?? ESC k kill-sentence
ESC C- indent-region ESC l downcase-word
ESC SPC just-one-space ESC m back-to-indentation
ESC ! shell-command ESC q fill-paragraph
ESC $ spell-word ESC r move-to-window-line
ESC % query-replace ESC t transpose-words
ESC ' abbrev-prefix-mark ESC u upcase-word
ESC ( insert-parentheses ESC v scroll-down
ESC ) move-past-close-and-reindent ESC w copy-region-as-kill
ESC , tags-loop-continue ESC x execute-extended-command
ESC - negative-argument ESC y yank-pop
ESC . find-tag ESC z zap-to-char
ESC 0 .. ESC 9 digit-argument ESC | shell-command-on-region
ESC ; indent-for-comment ESC ~ not-modified
ESC < beginning-of-buffer ESC DEL backward-kill-word

C-x 4 C-f find-file-other-window C-x 4 d dired-other-window
C-x 4 . find-tag-other-window C-x 4 f find-file-other-window
C-x 4 b pop-to-buffer C-x 4 m mail-other-window