多层应用程序中的Hibernate依赖关系位置

时间:2015-01-05 15:01:23

标签: java hibernate maven jpa multi-tier

我有一个关于hvennate-annotations jar在我的maven项目中的位置的具体问题。

我的项目包含三个模块。客户端和服务器模块都取决于共享模块。 Maven构建了两个用于部署的软件包:Client + Shared和Server + Shared。

带注释的Hibernate实体位于Shared模块中,因为我需要在客户端和服务器之间传递它们(通过RMI)。

现在出现了我的问题。 hibernate-annotations.jar用作Shared模块的依赖项,以允许编译Hibernate实体。库本身依赖于hibernate-core。结果,我在已部署的客户端应用程序中有hibernate库,即使我不是真的需要它们。罐子很大,我想让客户尽可能地保持苗条。

是否有一些既定的技术可以避免这个问题?我想到的是使用基于XML的Hibernate配置,因此我可以将Hibernate依赖项移动到Server模块,但我想坚持使用注释。

感谢。

2 个答案:

答案 0 :(得分:1)

我认为你应该在你的pom中使用scope标记作为依赖项。

看看这个并选择合适的一个:http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html

据我所知,如果你只需要编译时的依赖,你应该使用范围“编译”等等

希望这会对你有帮助!

答案 1 :(得分:1)

您可以在客户端的pom.xml中排除共享依赖项的一个或多个传递依赖项。这里假设共享项目具有组ID" org.shared",工件ID"共享"和版本" 0.0.1-SNAPSHOT":

<dependency>
  <groupId>org.shared</groupId>
  <artifactId>shared</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <exclusions>
    <exclusion>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-core</artifactId>
    </exclusion>
    ...
  </exclusions>
</dependency>
相关问题