使用Maven和m2e插件在Eclipse中添加hibernate依赖项

时间:2014-03-30 20:22:56

标签: eclipse hibernate maven dependencies m2e

我在eclipse中创建了一个Java项目,并将hibernate 3.5.4依赖项添加到pom.xml文件中,但是Maven Dependencies选项卡中唯一出现的jar是slf4j-api-1.5.8.jar。我应该如何配置Maven或m2e插件来为Hibernate添加所有必需的依赖项?

我的pom.xml文件:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>pl.edu.agh.bd2.tutorial</groupId>
  <artifactId>HibernateTutorial</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
          <source>1.3</source>
          <target>1.2</target>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate</artifactId>
        <version>3.5.4-Final</version>
        <type>pom</type>
    </dependency>
  </dependencies>
</project>

1 个答案:

答案 0 :(得分:4)

使用<type> pom指定依赖项时,它不会像您期望的那样包含在依赖项库中(jar文件)。 以下是我用来包含的基本hibernate工件ID列表:

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>${hibernate.version}</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>${hibernate.version}</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate.common</groupId>
        <artifactId>hibernate-commons-annotations</artifactId>
        <version>${hibernate.version}</version>
        <classifier>tests</classifier>
    </dependency>
    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.0-api</artifactId>
        <version>1.0.1.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>${hibernate.version}</version>
    </dependency>

${hibernate.version}替换为所需版本,或使用此标识符定义属性。