【问题标题】:Adding hibernate dependency in Eclipse with Maven and m2e plugin使用 Maven 和 m2e 插件在 Eclipse 中添加休眠依赖项
【发布时间】:2014-03-31 20:39:26
【问题描述】:

我在 Eclipse 中创建了一个 Java 项目,并将 hibernate 3.5.4 依赖项添加到 pom.xml 文件中,但出现在 Maven 依赖项选项卡中的唯一 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>

【问题讨论】:

  • 你能给我们看看你所做的 pom.xml 吗?

标签: eclipse hibernate maven dependencies m2e


【解决方案1】:

当使用 &lt;type&gt; pom 指定依赖项时,它不会像您期望的那样包含在您的依赖项库中(一个 jar 文件)。 这是我用来包含的基本休眠工件 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} 替换为所需版本或使用此标识符定义属性。

【讨论】:

    猜你喜欢
    • 2013-09-28
    • 2012-01-20
    • 2012-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-16
    • 1970-01-01
    • 2020-09-09
    相关资源
    最近更新 更多