为什么要用耳朵而不是战争?
I read this and this which are somewhat related to my question. But I came across this article that says that EJBs can be packaged in a war file. If this is the case, why is there a need for an ear? An explanation with an example will be highly appriciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 EAR 或 WAR 取决于您想要部署它的服务器、您的应用程序以及您的个人偏好。从 Java EE6 开始,您可以将 EJB 与其他 servlet、jsps 等一起打包到 WAR 文件中(最终得到的 Web 应用程序只能部署在 Java EE 6 兼容服务器上)。如果您以旧方式将应用程序打包为单独的包中的 ejb 并分别将其打包,则可以使用 java ee 5 服务器,如果您尚未在应用程序中使用 java ee6 的其他功能,则可以将 EJB 和 WAR 的部署分开明确分离业务层 (EJB) 和视图(Servlet、JSP 等)。
Using EAR or WAR depends on the server you want to deploy it, your application, and on your personal preferences. From Java EE6 you can package your EJBs together with other servlets, jsps etc into WAR file (you end up with web application which you can deploy only on java ee 6 compatible server). If you package your app the old way with ejbs in a separate package and war separately, you can use java ee 5 server if you haven't used other features of java ee6 within your application, you can separate the deployments of your EJBs and WARs to have a clear separation of your business layer (EJB) and your view (Servlets, JSP's etc).
使用 EAR 可以实现业务之间的彻底分离(通常是无状态 EJB bean,提供后端/数据库相关服务,原则上可以由非 Web 客户端使用)和前端(xhtml 文件、JSF 支持 bean 等)。
我通常遵循以下约定,对于给定的项目,说“foo”:
构建 foo-war.war 只需要 foo-client.jar
构建 foo-ejb .jar只需要foo-client.jar。
EAR 中的结构是:
当您的代码部署为 WAR 时,也许有一种方法可以实现类似的干净分离,但上面是我正在使用的并且似乎对我有用(我开放当然是建议)。
Using an EAR affords a clean separation between business (usually stateless EJB beans that provide back-end / db-related services and can in principle be used by non-web clients) and front-end (xhtml files, JSF backing beans, etc).
I usually follow the below convention, for a given project, say "foo":
Building foo-war.war only requires foo-client.jar
Building foo-ejb.jar only requires foo-client.jar.
The structure in the EAR is:
There maybe a way to have a similarly clean separation when your code is deployed as a WAR but the above is what I am using and seems to work for me (I am open to suggestions of course).
Java EE 平台对企业应用程序使用分布式多层应用程序模型。应用程序逻辑根据功能分为组件,构成 Java EE 应用程序的应用程序组件安装在不同的机器上,具体取决于应用程序组件所属的多层 Java EE 环境中的层。
下图显示了两个多层 Java EE 应用程序,它们分为以下列表中描述的层。此图中显示的 Java EE 应用程序部分在 Java EE 组件中呈现。
客户端层组件在客户端计算机上运行。
Web 层组件在 Java EE 服务器上运行。
业务层组件在 Java EE 服务器上运行。
企业信息系统 (EIS) 层软件在 EIS 上运行
服务器。
尽管 Java EE 应用程序可以包含图 1-1 中所示的所有层,但 Java EE 多层应用程序通常被视为三层应用程序,因为它们分布在三个位置:客户端计算机、Java EE 服务器计算机和数据库或后端的旧机器。以这种方式运行的三层应用程序通过在客户端应用程序和后端存储之间放置多线程应用程序服务器来扩展标准的两层客户端和服务器模型。
因此,通常我们希望有 2 或 3 个独立的层:
-EAR (Enterprise应用程序ARchive)
-EJB(E企业JavaBeanseans)
-WAR(W< /strong>eb ARchive),
有时还有 JPA (Java Persistance API)
我希望您发现这很有用,
谢谢。
The Java EE platform uses a distributed multitiered application model for enterprise applications. Application logic is divided into components according to function, and the application components that make up a Java EE application are installed on various machines, depending on the tier in the multitiered Java EE environment to which the application component belongs.
The image down bellow shows two multitiered Java EE applications divided into the tiers described in the following list. The Java EE application parts shown in this image are presented in Java EE Components.
Client-tier components run on the client machine.
Web-tier components run on the Java EE server.
Business-tier components run on the Java EE server.
Enterprise information system (EIS)-tier software runs on the EIS
server.
Although a Java EE application can consist of all tiers shown in Figure 1-1, Java EE multitiered applications are generally considered to be three-tiered applications because they are distributed over three locations: client machines, the Java EE server machine, and the database or legacy machines at the back end. Three-tiered applications that run in this way extend the standard two-tiered client-and-server model by placing a multithreaded application server between the client application and back-end storage.
So usually we want to have 2 or 3 separated layers:
-EAR (Enterprise Application ARchive)
-EJB (Enterprise JavaBeans)
-WAR (Web ARchive)
and sometimes JPA (Java Persistance API)
I hope you find this useful,
Thanks.