繁体   English   中英

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

[英]Adding Hibernate 3.5.x to a maven pom.xml build

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

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

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

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

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

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.

正如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>

或者对于Hibernate Core:

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

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

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

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

这就是我设法将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>

. . .

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM