【问题标题】:Hibernate projects and Building with mavenHibernate 项目和使用 maven 构建
【发布时间】:2011-03-21 17:21:09
【问题描述】:

我正在尝试构建一个相对简单的项目,并将 Hibernate 与 maven 包括在内。我正在尝试使用 latest 版本的 Hibernate(3.5.4-Final)。

似乎 JBoss 人员最近更改了他们的 maven 存储库,我在让我的 maven 构建工作时遇到了一些问题。我在网上和这里找到了很多信息,但似乎没有什么能正常工作......我发现的很多信息都无法让我获得最新版本的 Hibernate。

我在 pom.xml 中定义了以下存储库:

<repository>
    <id>jboss-public-repository-group</id>
    <name>JBoss Public Repository Group</name>
    <url>https://repository.jboss.org/nexus/content/repositories/releases</url>
</repository>

我在 pom.xml 中定义了以下依赖项:

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

这似乎下载了一些依赖项,但不足以构建。

我收到以下错误:

下载:http://repo1.maven.org/maven2/org/hibernate/hibernate/3.5.4-Final/hibernate-3.5.4-Final.jar [信息] 无法在存储库中心 (http://repo1.maven.org/maven2) 中找到资源 'org.hibernate:hibernate:jar:3.5.4-Final'

我已经阅读了 JBoss 说要阅读 Maven Getting Started - Users 的页面,老实说,这对我来说没有任何意义。它说要把东西放在我的 settings.xml 中。我想将信息放在我的 pom.xml 中,而不要求每个人都修改 settings.xml。我几乎不是专家。我真的很想知道在我的 pom.xml 文件中放什么才能让它工作。

【问题讨论】:

标签: hibernate maven-2


【解决方案1】:

问题在于这个依赖

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate</artifactId>
    <version>3.5.4-Final</version>
    <!-- <type>jar</type> is implied here -->
</dependency>

只是一个 pom,而您试图将其作为 jar 引用。所以要引用它,你必须这样做:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate</artifactId>
    <version>3.5.4-Final</version>
    <type>pom</type>
</dependency>

这将抓住这个 pom 的传递依赖,但不是工件本身。 但是,pom only lists modules,而不是依赖项,因为它是休眠的根 pom。它对你没有帮助,别管它。

所以你真正想要的是要么

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

(对于经典休眠)或

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

(对于 jpa2 提供者)

【讨论】:

    【解决方案2】:

    嗯,我找到了答案……

    这会得到你需要的东西。从上面引用的页面中,将以下内容添加到您的 pom.xml:

    <repositories>
        <repository>
            <id>jboss-public-repository-group</id>
            <name>JBoss Public Maven Repository Group</name>
            <url>https://repository.jboss.org/nexus/content/groups/public/</url>
            <layout>default</layout>
            <releases>
                <enabled>true</enabled>
                <updatePolicy>never</updatePolicy>
            </releases>
            <snapshots>
                <enabled>true</enabled>
                <updatePolicy>never</updatePolicy>
            </snapshots>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>jboss-public-repository-group</id>
            <name>JBoss Public Maven Repository Group</name>
            <url>https://repository.jboss.org/nexus/content/groups/public/</url>
            <layout>default</layout>
            <releases>
                <enabled>true</enabled>
                <updatePolicy>never</updatePolicy>
            </releases>
            <snapshots>
                <enabled>true</enabled>
                <updatePolicy>never</updatePolicy>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>
    

    这是你需要的依赖:

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

    【讨论】:

    • 您无需声明pluginRepository 即可使用Hibernate。
    • 谢谢,刚刚为完全相同的问题节省了我大量的调试时间 :-)
    【解决方案3】:

    JBoss 已开始将自己的存储库与 Maven 中心同步为 posted on the JBoss community blog ,因此 hibernate 工件现在可用,而无需将 JBoss 存储库添加到您的 pom.xml 或存储库管理器。

    Search result for hibernate-core:

    要将 Hibernate Core 3.6.3 添加到您的项目中,只需将以下 sn-p 添加到您的 pom 中:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-11-10
      • 1970-01-01
      • 2023-01-20
      • 2013-02-21
      • 2014-05-16
      • 2013-09-28
      • 1970-01-01
      相关资源
      最近更新 更多