1

我有一个基于 Maven 的 J2EE 项目结构

Customer (root pom)
   |
   |------ WebTier (JSF 2/Primefaces)
   |
   |------ BusinessTier (EJB 3.*, interfaces, interface impl)
   |
   |------ PersistenceTier (JPA 2)
   |
   |------ CustomerEar

现在我发现我需要一个或多个新的 Java 类来处理基本例程,我想将这个 Utility 类放在 WebTier 下并不是一个好主意,因为 Utilities 也可能在 BusinessTier 中使用。创建一个独立的 Java 项目,实现必要的类并将这个 jar 包含在耳朵里,这是“最佳实践”吗?

4

2 回答 2

0

It would be hard to try and justify a "best practice" in this kind of situation as it is a very project-specific question.

There would be nothing inherently wrong with adding a "CommonLibrary" project or such-like that is a dependency of both the WebTier and BusinessTier. In fact the project I am working on now is almost exactly that structure (with a common library).

As this is a maven project, just make sure the "CommonLibrary" project dependecy scope is set to "provided" in the Business/Web/Persistence tiers, and "compile" in the ear project.

e.g. In WebTier, the dependency would be:

<dependency>
   <groupID>group.name</groupID>
   <artifactID>common-library</artifactID>
   <scope>provided</scope>
</dependency>

EDIT: The scope would be 'provided' in the Web Tier as it would be a .war. The other tiers would be jars so the scope can be 'compile' for the persistence and business tiers.

于 2013-10-25T10:21:40.527 回答
0

根据我的经验,我建议为实用程序设置单独的项目文件夹,并将其作为 jar 包含在需要的地方

优点是

  1. 易于维护,因为您需要更改一次代码。

  2. 需要时插入和拔出。

  3. 您可以将其作为常见的并用于其他项目。

例如

阿帕奇字符串实用程序

http://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/StringUtils.html

豆工具

http://commons.apache.org/proper/commons-beanutils/

于 2013-10-25T10:25:20.513 回答