Java EE 项目的架构 [英] Architecture of a Java EE project

查看:31
本文介绍了Java EE 项目的架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有 EAR 和 4 个 WAR 的 Java EE 项目.我有一些在战争中使用的 pojo.它们是包含静态变量和方法的类,并且在 WAR 中应该是相同的.它们应该放在哪里?

I have a Java EE project with an EAR and 4 WARs. I have some pojos that are used in the wars. They are classes which contain static variables and methods and should be the same across the WARs. Where should they be placed?

一些背景:我继承了其中一场战争中经常使用的 pojo 的项目.但是,我希望所有 4 个 WAR 都引用一些新的静态访问类的同一个实例.在其中一场战争中,这是不可能的,因为每个 WAR 似乎都采用它自己的静态类的运行时实例,并且更改一个 WAR 中的类,不会导致另一个 WAR 中的类发生更改.

Some background: I had inherited the project with the frequently used pojos in one of the wars. However I wanted all 4 of the WARs to refer to the same instance of some new staticly accessed classes. This was not possible with them held in one of the wars, as each WAR appeared to take it's own runtime instance of the static classes, and changing the class in one WAR, did not result in a change to the class in another WAR.

因此,为了解决这个问题,我将其安装在 JAR 中并将其部署到服务器.但是现在每次部署项目时,JAR 也必须构建并安装在服务器上,如果它发生了变化.

So to combat this I installed in a JAR and deployed that to the server. But now every time the project is deployed the JAR must also be built and installed on the server too if it has changed.

在这里部署的人不喜欢这种架构,我想知道是否有其他方法可以做到?

The person who deploys that here doesn't like this architecture and I wondered if there was another way to do it?

推荐答案

是的,WAR 文件将在各自的类加载器下加载,因此它们看不到彼此的类.

Yes, WAR files will each be loaded under their own classloader, so they do not see each other's classes.

您可以在 EAR 的根目录中放置一个 JAR 文件,并在每个 WAR 的清单中引用它.这些 JAR 有时称为实用 JAR".

You can place a JAR file in the root of the EAR and refer to it in the Manifest of each each WAR.These JARs are sometimes called "utility JARs".

我同意这种独立的部署比在其他地方有一个单独的 JAR 文件更可取.

I agree that a self-contained deployment of this kind is preferable to having a separate JAR file somewhere else.

这篇关于Java EE 项目的架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆