Ejb 简明教程

EJB - Packaging Applications

使用 EJB 3.0 打包应用程序的要求类似于 J2EE 平台的要求。EJB 组件打包为 jar 文件形式的模块,并打包为 ear 文件形式的应用程序企业存档。

Requirement of Packaging applications using EJB 3.0 are similar to that of J2EE platform. EJB components are packaged into modules as jar files and are packaged into application enterprise archive as ear file.

任何企业应用程序主要有三个组件 −

There are majorly three components of any enterprise application −

  1. jar − Java Application aRchive, containing EJB modules, EJB client modules and utility modules.

  2. war − Web Application aRchive, containing web modules.

  3. ear − Enterprise Application aRchive, containing jars and war module.

ear structure

在 NetBeans 中,创建、开发、打包和部署 J2EE 应用程序非常容易。

In NetBeans, it is very easy to create, develop, package, and deploy the J2EE applications.

在 NetBeans IDE 中,选择 File > New Project > 。在“Category”下选择工程类型, Java EE ,工程类型作为 Enterprise Application 。单击 Next > 按钮。输入工程名称和位置。单击 Finish > 按钮。我们已经选择 EnterpriseApplicaton 这个名称。

In NetBeans IDE, select ,File > New Project >.Select project type under category,Java EE, Project type as Enterprise Application. Click Next > button. Enter project name and location. Click Finish > button. We’ve chosen name as EnterpriseApplicaton.

选择服务器和设置。保持 Create EJB ModuleCreate Web Application Module 被选中,并为其提供默认名称。单击“Finish”按钮。NetBeans 将在工程窗口中创建以下结构。

Select Server and Settings. Keep Create EJB Module and Create Web Application Module checked with default names provided. Click finish button. NetBeans will create the following structure in project window.

ear project

右键单击工程资源管理器中的工程 Enterprise Application ,然后选择“Build”。

Right click on the Project Enterprise Application in project explorer and select Build.

ant -f D:\\SVN\\EnterpriseApplication dist
pre-init:
init-private:
init-userdir:
init-user:
init-project:
do-init:
post-init:
init-check:
init:
deps-jar:
deps-j2ee-archive:
EnterpriseApplication-ejb.init:
EnterpriseApplication-ejb.deps-jar:
EnterpriseApplication-ejb.compile:
EnterpriseApplication-ejb.library-inclusion-in-manifest:

Building jar: D:\SVN\EnterpriseApplication\EnterpriseApplication-ejb\dist\EnterpriseApplication-ejb.jar

EnterpriseApplication-ejb.dist-ear:
EnterpriseApplication-war.init:
EnterpriseApplication-war.deps-module-jar:
EnterpriseApplication-war.deps-ear-jar:
EnterpriseApplication-ejb.init:
EnterpriseApplication-ejb.deps-jar:
EnterpriseApplication-ejb.compile:
EnterpriseApplication-ejb.library-inclusion-in-manifest:
EnterpriseApplication-ejb.dist-ear:
EnterpriseApplication-war.deps-jar:
EnterpriseApplication-war.library-inclusion-in-archive:
EnterpriseApplication-war.library-inclusion-in-manifest:
EnterpriseApplication-war.compile:
EnterpriseApplication-war.compile-jsps:
EnterpriseApplication-war.do-ear-dist:

Building jar: D:\SVN\EnterpriseApplication\EnterpriseApplication-war\dist\EnterpriseApplication-war.war

EnterpriseApplication-war.dist-ear:
pre-pre-compile:
pre-compile:
Copying 1 file to D:\SVN\EnterpriseApplication\build
Copying 1 file to D:\SVN\EnterpriseApplication\build
do-compile:
post-compile:
compile:
pre-dist:
do-dist-without-manifest:
do-dist-with-manifest:

Building jar: D:\SVN\EnterpriseApplication\dist\EnterpriseApplication.ear

post-dist:
dist:
BUILD SUCCESSFUL (total time: 1 second)

在这里你可以看到,Netbeans 首先准备 Jar,然后是 War,最后是携带 jar 和 war的文件的 ear 文件。每个 jar、war 和 ear 文件都包含一个 meta-inf 文件夹,以根据 J2EE 规范提供元数据。

Here you can see, that Netbeans prepares Jar first, then War and in the end, the ear file carrying the jar and war, file. Each jar,war and ear file carries a meta-inf folder to have meta data as per the J2EE specification.