【问题标题】:Maven - how to add all required dependencies for hibernate?Maven - 如何为休眠添加所有必需的依赖项?
【发布时间】:2016-02-16 15:56:58
【问题描述】:

我从 Hibernate 网站下载了 zip,我们有一个文件夹,其中包含所有必需的 jar。

但我想用 Maven 来做这件事。我是否需要检查此 Hibernate 版本所需的库并在 pom.xml 中手动添加它们?

有没有办法只添加 hibernate 和 maven 来添加所有必需的库本身?

【问题讨论】:

  • hibernate-core 在存储库中搜索。添加依赖项。

标签: java hibernate maven


【解决方案1】:

如果你想在 Hibernate 中使用 JPA,你只需要一个 Maven 依赖项。参考download page:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>5.4.10.Final</version>
</dependency>

此依赖项会将所有必需的其他工件作为传递依赖项(如 JPA API、Hibernate Core 和许多其他)。

这就是 Maven 的力量。您无需手动向类路径添加任何内容,也无需自己确定应该添加哪些 jar。一个 Maven 依赖项会将它需要的所有东西都声明为传递依赖项。

【讨论】:

【解决方案2】:

当使用 pom.xml 指定依赖项时,它不会像您期望的那样包含在您的依赖项库中(一个 jar 文件)。这是我用来包含的基本休眠工件 ID 的列表:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>${hibernate.version}</version>
</dependency>
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-validator</artifactId>
    <version>${hibernate.version}</version>
</dependency>
<dependency>
    <groupId>org.hibernate.common</groupId>
    <artifactId>hibernate-commons-annotations</artifactId>
    <version>${hibernate.version}</version>
    <classifier>tests</classifier>
</dependency>
<dependency>
    <groupId>org.hibernate.javax.persistence</groupId>
    <artifactId>hibernate-jpa-2.0-api</artifactId>
    <version>1.0.1.Final</version>
</dependency>
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>${hibernate.version}</version>
</dependency>

将 ${hibernate.version} 替换为所需版本或使用此标识符定义属性。

【讨论】:

    【解决方案3】:
    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-core</artifactId>
      <version>5.0.2.Final</version>
    </dependency>
    

    【讨论】:

      【解决方案4】:

      可以使用 hibernate-core 依赖项设置基本核心实现(包括 JPA)Hibernate 配置

          <dependency>
              <groupId>org.hibernate</groupId>
              <artifactId>hibernate-core</artifactId>
              <version>5.2.16.Final</version>
          </dependency>
      

      这将传递以下依赖项,

      参考:http://hibernate.org/orm/releases/5.2/

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-10-11
        • 2017-08-17
        • 2020-11-30
        • 2015-07-12
        • 2016-07-03
        • 1970-01-01
        • 2014-10-26
        相关资源
        最近更新 更多