代码之家  ›  专栏  ›  技术社区  ›  James Adams

如何使用Maven获得最新的Hibernate版本?

  •  35
  • James Adams  · 技术社区  · 16 年前

    我很难通过maven依赖获得hibernate的最新版本。看来,最新的I可以从Maven中央存储库获取3.2.6Ga,并且我对使用3.3.2.Ga感兴趣,这是在HiBurn.Org站点上显示的最新版本。当我在项目的pom.xml中将hibernate依赖项修改为此最新版本时,在运行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验证器依赖项,它也需要在本地安装,在那一点上,我停下来四处看看是否有更好的方法,也许是把maven指向jboss/hibernate存储库,与我使用的其他重要的open cource包(如spring或junit)相比,这真的是一个头疼的问题——当有一个新版本发布时,我所做的只是更新dependency元素中的版本号,它就工作了。

    我已经尝试过将下面的存储库声明添加到pom.xml中,但毫无乐趣:

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

    我在谷歌上搜索了一下,没有找到什么有用的东西。有人建议使用最新版本的Hibernate或Hibernate核心(3.3.2.GA)、Hibernate验证器(3.1.0)和Hibernate注释(3.4.0)来进行最直接的方式吗?

    7 回复  |  直到 8 年前
        1
  •  36
  •   Robert Munteanu    14 年前

    jboss已经开始将自己的repo与maven central as同步。 posted on the JBoss community blog 因此 hibernate 工件现在是可用的,无需将jboss存储库添加到 pom.xml 或存储库管理器。

    Search result for hibernate-core :

    search result for hibernate-core

    要将HibernateCore3.6.3添加到项目中,只需将以下代码片段添加到POM中:

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>3.6.3.Final</version>
    </dependency>
    
        2
  •  16
  •   Rich Seller    16 年前

    您遇到了问题,因为org.hibernate:hibernate:3.3.2.ga是一个聚合器pom,用于构建其余模块,实际上它不是一个jar。看起来3.2.7之后发生了一次重构,这让人大吃一惊。作为参考 blog entry 提示他们在将hibernate升级到central的过程中遇到了一些问题,也许可以解释这种变化。

    如果你看看 JBoss repository ,您将看到3.3.2.ga的hibernate模块 托管的,它们只是作为单独的工件、hibernate core、hibernate ehcache等托管的。因此,您的存储库声明是正确的,您只需要微调依赖关系声明以考虑更改。

    jboss存储库托管 hibernate-annotations-3.4.0.GA , hibernate-validator-3.1.0.GA hibernate-core-3.3.2.GA 其中之一。尝试将特定的构件添加到pom中,并使用已经声明的jboss存储库。

    还有一个 hibernate-dependencies 为大多数hibernate工件(包括core)提供可传递依赖关系的pom。所以最简单的方法就是替换现有的 冬眠 依赖关系声明 休眠依赖项

    你的依赖关系会这样结束…

    <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团队提供了该项目,那就更好了)。

        3
  •  4
  •   Rich Seller    16 年前

    这很令人沮丧,但新版本只是没有,并没有很长一段时间。具有讽刺意味的是,hibernate工件有一些相当复杂的相互依赖关系,并且这些依赖关系的最低版本都有很好的文档记录,这些依赖关系可以理想地表示为maven pom。相反,我们必须自己下载二进制文件并尝试在本地表达它们。

        4
  •  2
  •   Martijn Pieters    8 年前

    您可以在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>
    
        5
  •  1
  •   Sanne    12 年前

    这个问题已经过时很久了: 多年以来,所有hibernate版本都在maven central中提供。

    查看www.hibernate.org获取最新的maven坐标(不要相信IDE的建议)。

        6
  •  0
  •   Salandur    16 年前

    存储库中缺少jar,这可能是最新的hibernate版本不在主存储库中的原因。

        7
  •  0
  •   jsh    14 年前

    对这件事还不熟悉,还到处玩弄。我没有完整的解决方案,但是:

    看来我可以通过包括解决几个依赖 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

    抱歉,刚刚意识到有些是多余的,但希望它有助于一些人看到其他可能的网址。JB

    推荐文章