Java 将 Hibernate 3.5.x 添加到 maven pom.xml 构建

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3018719/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 15:37:53  来源:igfitidea点击:

Adding Hibernate 3.5.x to a maven pom.xml build

javahibernatemaven-2

提问by benstpierre

I added the JBoss Maven repo to my pom.xml file like this...

我像这样将 JBoss Maven repo 添加到我的 pom.xml 文件中......

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

And I added Hibernate itself like this...

我像这样添加了 Hibernate 本身......

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

But when I try to build my application I see this error....

但是当我尝试构建我的应用程序时,我看到了这个错误......

Downloading: http://repository.jboss.org/maven2//org/hibernate/hibernate/3.5.1-Final/hibernate-3.5.1-Final.jar
[INFO] Unable to find resource 'org.hibernate:hibernate:jar:3.5.1-Final' in repository jboss (http://repository.jboss.org/maven2/)
Downloading: http://repo1.maven.org/maven2/org/hibernate/hibernate/3.5.1-Final/hibernate-3.5.1-Final.jar
[INFO] Unable to find resource 'org.hibernate:hibernate:jar:3.5.1-Final' in repository central (http://repo1.maven.org/maven2)
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Failed to resolve artifact.

Missing:
----------
1) org.hibernate:hibernate:jar:3.5.1-Final

  Try downloading the file manually from the project website.

  Then, install it using the command: 
      mvn install:install-file -DgroupId=org.hibernate -DartifactId=hibernate -Dversion=3.5.1-Final -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 -Dversion=3.5.1-Final -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]

  Path to dependency: 
    1) stakeholdersupdate:stakeholdersupdate:war:1.0
    2) org.hibernate:hibernate:jar:3.5.1-Final

----------
1 required artifact is missing.

采纳答案by Pascal Thivent

As seanizermentioned, the org.hibernate:hibernate:pom:3.5.1-Finalartifact is an aggregating modules of type pom(it aggregates the Hibernate Core modules). So you could indeed depend on it by specifying a <type>pom</type>. But I would personally declare a dependency on the wanted module, for example for Hibernate Entity Manager:

正如seanizer 所提到的,org.hibernate:hibernate:pom:3.5.1-Final工件是一个聚合模块类型pom(它聚合了 Hibernate Core 模块)。所以你确实可以通过指定一个<type>pom</type>. 但是我个人会声明对所需模块的依赖,例如对于 Hibernate Entity Manager:

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

Or for Hibernate Core:

或者对于 Hibernate 核心:

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

回答by Sean Patrick Floyd

the hibernate artifact is of type pom (meaning it is only a wrapper for other projects). do this:

休眠工件是 pom 类型(意味着它只是其他项目的包装器)。做这个:

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

(if you leave out the type, maven will try to resolve the artifact as a jar, which doesn't exist in this case)

(如果您省略类型,maven 会尝试将工件解析为 jar,在这种情况下不存在)

回答by aurelije

This is how I managed to add Hibernate and JPA 2 to my project

这就是我设法将 Hibernate 和 JPA 2 添加到我的项目的方式

. . .

<repositories>
    <repository>
        <id>JBoss</id>
        <name>The "public-jboss" repository group provides a combined view all JBoss community project artifacts</name>
        <layout>default</layout>
        <url>http://repository.jboss.org/nexus/content/groups/public-jboss</url>
    </repository>
</repositories>

<dependencies>

    . . .

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

    . . .

</dependencies>

. . .