Architecture of a Java EE project

2019-08-10 06:56发布

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?

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.

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?

1条回答
smile是对你的礼貌
2楼-- · 2019-08-10 07:41

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

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".

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

查看更多
登录 后发表回答