本文介绍了部署Java应用程序(Tomcat / Glassfish)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们目前正在为大学开展一个项目,我们希望将其作为逻辑模块和UI模块来实施。我们在部署Web应用程序方面的经验不多,但我们提出了以下几种备选方案:


  1. 将其部署为单个WAR项目我们有关于将UI与应用程序的后端进行通信的问题)。
  2. 使用webservices在同一台服务器上部署两个WAR项目,以便在项目之间进行通信。 (我们有一个使用这种方法的原型,部署在Tomcat服务器上)
  3. 部署一个WAR项目和EJB项目。

  4. 部署一个EAR项目,包含对WAR和EJB项目的引用。 (我们有一个使用Glassfish服务器上部署的这种方法的原型)

我们想知道这些替代方法是否不正确,或者如果有任何替代方案比另一方更好。具体而言,为什么将项目部署为EAR模块是有用的(或不是)?



项目现在开始,所以我们只会处理一对夫妇数百个用户现在。但是,如果项目成功,我们需要处理几百万个用户。

解决方案

尽管Tomcat是一个servlet容器,但如果你需要EJB,你需要像,这可能是有趣的。


We are currently working on a project for college which we would like to implement as a logic module and UI module. We have little experience deploying web applications, however we came up with the following alternatives:

  1. Deploy it as a single WAR project (which would solve the problem we have about communicating the UI with the backend of our application).
  2. Deploy two WAR projects in the same server using webservices for communication between the projects. (We have a prototype using this approach deployed on a Tomcat server)
  3. Deploy a WAR project and EJB project.
  4. Deploy an EAR project which would contain the references to the WAR and EJB projects. (We have a prototype using this approach deployed on a Glassfish server)

We would like to know if any of these alternatives is incorrect, or if any of the alternatives is better than the other. Specifically, why would it be useful (or not) to deploy the project as an EAR module?

The project right now is starting, so we will only be handling a couple hundreds of users right now. However, if the project succeeds we would need to deal with a couple million of users.

解决方案

None of the alternatives are incorrect, though Tomcat is a servlet container, if you want EJBs there you'd need something like TomEE which is Tomcat extended to full EE support. Or use that Glassfish.

What's best depends on your specific requirements: do you need / value more the decoupling of modules or would you rather have the consistency and reliability you get bundling things together. EJBs also have some additional benefits that might be of interest, but they're not relevant for every project. Note that in addition to alternatives mentioned, there are others, such as JMS-based communication, HTTP REST communication and using OSGi to decouple the packages.

About why it would be useful to deploy the project as an EAR module, quoting wikipedia: "EAR (Enterprise ARchive) is a file format used by Java EE for packaging one or more modules into a single archive so that the deployment of the various modules onto an application server happens simultaneously and coherently. It also contains XML files called deployment descriptors which describe how to deploy the modules.". So basically you get the benefits of coupling that boils down to reliability, you'd always know how your modules are deployed in contrast to each other. EAR modules supports EE mechanisms, such as EJB modules, very well and you get a controllable container.

There already exists a thread When is it appropriate to use an EAR and when should your apps be in WARs?, which might be of interest.

这篇关于部署Java应用程序(Tomcat / Glassfish)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 20:37
查看更多