36

我无法通过 Maven 依赖项获取最新版本的 Hibernate。看来我可以从 Maven 中央存储库获取的最新版本是 3.2.6.GA,我有兴趣使用 3.3.2.GA,这是 hibernate.org 网站上显示的最新版本。当我在我的项目的 pom.xml 中将我的休眠依赖项修改为这个最新版本时,我在运行 Maven 构建时收到以下错误:

Missing:
----------
1) org.hibernate:hibernate:jar:3.3.2.GA

  Try downloading the file manually from the project website.

  Then, install it using the command:
      mvn install:install-file -DgroupId=org.hibernate -DartifactId=hibernate -D
version=3.3.2.GA -Dpackaging=jar -Dfile=/path/to/file

  Alternatively, if you host your own repository you can deploy the file there:

      mvn deploy:deploy-file -DgroupId=org.hibernate -DartifactId=hibernate -Dve
rsion=3.3.2.GA -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[
id]

一旦我这样做了,我会继续收到错误消息,表明我需要添加一个 javassist 依赖项,然后我需要更新我的 hibernate-validator 依赖项,它也需要在本地安装,然后我停下来环顾四周,看看是否有更好的方法,可能将 Maven 指向 JBoss/Hibernate 存储库等。与我使用的其他重要的开源软件包(如 Spring 或 JUnit)相比,这似乎真的很让人头疼——当有一个新版本发布时,我做的是更新依赖元素中的版本号,它就可以工作。

我尝试将以下存储库声明添加到我的 pom.xml 中,但没有任何乐趣:

<repositories>
    <repository>
        <id>jboss</id>
        <url>http://repository.jboss.org/maven2</url>
    </repository>
</repositories>

我搜索了谷歌并没有找到太多帮助。有人可以建议使用最新版本的 hibernate 或 hibernate-core (3.3.2.GA)、hibernate-validator (3.1.0) 和 hibernate-annotations (3.4.0) 的最直接的方法吗?

4

7 回答 7

36

JBoss 已经开始将他们自己的存储库与JBoss 社区博客上发布的Maven 中心同步,因此hibernate现在可以使用工件,而无需将 JBoss 存储库添加到您的pom.xml存储库管理器或存储库管理器。

休眠核心的搜索结果

休眠核心的搜索结果

要将 Hibernate Core 3.6.3 添加到您的项目中,只需将以下代码段添加到您的 pom 中:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>3.6.3.Final</version>
</dependency>
于 2011-05-25T05:58:48.527 回答
17

您遇到问题是因为 org.hibernate:hibernate:3.3.2.GA 是用于构建其余模块的聚合器 POM,它实际上并不是一个 jar。看起来在 3.2.7 之后发生了重构,这让人们望而却步。作为参考,这个博客条目暗示了他们在将 Hibernate 提升到中央时遇到的问题,并可能解释这种变化。

如果您查看JBoss 存储库,您会看到 3.3.2.GA 的休眠模块托管的,它们只是作为单独的工件、hibernate-core、hibernate-ehcache 等托管的。所以您的存储库声明是正确的,您只需要微调依赖声明以将更改考虑在内。

JBoss 存储库托管hibernate-annotations-3.4.0.GAhibernate-validator-3.1.0.GAhibernate-core-3.3.2.GA等。尝试将特定工件添加到您的 POM 并使用您已经声明的 JBoss 存储库。

还有一个hibernate-dependencies pom 为大多数 hibernate 工件(包括核心)提供传递依赖。所以最简单的做法是用hibernate-dependencies替换你现有的hibernate依赖声明

你的依赖最终会像这样......

<dependencies>
  <dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-dependencies <!--or hibernate-core--></artifactId>
    <version>3.3.2.GA</version>
    <type>pom</type>
    <!--hibernate-dependencies is a pom, not needed for hibernate-core-->
  </dependency>
  <dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-annotations</artifactId>
    <version>3.4.0.GA</version>
  </dependency>
  <dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-validator</artifactId>
    <version>3.1.0.GA</version>
  </dependency>
  ...
  <!--any other hibernate deps not inherited transitively-->

为了让你的生活更简单,你可以在一个名为(hibernate-all)的项目中定义所有这些hibernate依赖项,然后为所有使用hibernate的项目引用该单个项目(当然,如果hibernte团队提供了该项目,那就太好了)。

于 2009-08-05T21:54:36.727 回答
4

It's frustrating, but the newer versions just aren't there, and haven't been for a long time. The irony is that the Hibernate artifacts have some fairly intricate inter-dependencies and well-documented minimum versions of those dependencies, which would be ideally represented as a Maven POM. Instead, we have to download the binaries ourselves and try and express them locally.

于 2009-08-05T07:46:06.183 回答
2

您可以在 pom.xml 中使用依赖项

<dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate</artifactId>
            <version>3.2.6.ga</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-annotations</artifactId>
            <version>3.3.1.GA</version>
        </dependency>
于 2012-12-13T04:12:47.127 回答
1

这个问题已经过时了很久了:多年来所有的 Hibernate 版本都在 Maven 中心可用。

检查 www.hibernate.org 以获得最新的 Maven 坐标(不要相信你的 IDE 的建议)。

于 2013-11-05T10:47:54.773 回答
0

存储库中缺少罐子,也许这就是最新的休眠版本不在主存储库中的原因

于 2009-08-05T07:41:22.823 回答
0

对此并不陌生,并且正在玩弄它。我没有完整的解决方案但是:

似乎我能够通过包含http://repository.jboss.com/maven3/而不是 maven 2 来解决一些依赖关系。

对于那些仍然存在问题的人,可以作为最后一根稻草从 maven 站点下载丢失的文件,例如,浏览:

http://repo1.maven.org/maven2/org/hibernate/hibernate-core/3.6.8.Final/

(是的,我尝试将此路径和其他合理路径设置为存储库源,但没有成功......)

要将这个 jar 安装到您的 Maven 构建中,请执行以下操作:

mvn install:install-file -Dfile=path/to/jar/hibernate-core-3.6.8.Final.jar -DgroupId=org.hibernate -DartifactId=hibernate-core -Dversion=3.6.8-Final -Dpackaging=jar

参考:http ://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html

抱歉,刚刚意识到其中一些是多余的,但希望看到其他可能的 URL 对某些人有所帮助。- JB

于 2011-12-01T18:47:28.553 回答