Java Maven - 如何为休眠添加所有必需的依赖项?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33720355/
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
Maven - how to add all required dependencies for hibernate?
提问by Alexander Nikolov
I have downloaded the zip from the Hibernate website and we have a folder which contains all required jars.
我已经从 Hibernate 网站下载了 zip,我们有一个包含所有必需 jar 的文件夹。
But I want to to this with Maven. Do I need to check which are the required libraries for this Hibernate version and add them manually in the pom.xml
?
但我想用 Maven 做到这一点。我是否需要检查此 Hibernate 版本所需的库并在pom.xml
.
Is there a way just to add hibernate and maven to add all required libraries itself?
有没有办法只添加 hibernate 和 maven 来添加所有必需的库本身?
采纳答案by Tunaki
If you want to use JPA with Hibernate, you only need a single Maven dependency. Refer to the download page:
如果您想在 Hibernate 中使用 JPA,您只需要一个 Maven 依赖项。参考下载页面:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.4.10.Final</version>
</dependency>
This dependency will pull all the required other artifacts as transitive dependencies (like the JPA API, Hibernate Core and a lot of others).
此依赖项会将所有必需的其他工件作为传递依赖项(如 JPA API、Hibernate Core 和许多其他)拉取。
This is the power of Maven. You don't need to add anything manually to the classpath or figure out yourself which jars you should add. One Maven dependency will declare as transitive dependencies everything that it needs.
这就是 Maven 的力量。您不需要手动向类路径添加任何内容,也不需要自己弄清楚应该添加哪些 jar。一个 Maven 依赖将把它需要的一切都声明为传递依赖。
回答by Abdelhak
When specifying a dependency with pom.xml it won't be included into your dependencies library as you are expecting (a jar file). Here is a list of basic hibernate artifact ids that I use to include:
当使用 pom.xml 指定依赖项时,它不会像您期望的那样包含在您的依赖项库中(一个 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>
Replace the ${hibernate.version} with desired version or define a property with this identifier.
将 ${hibernate.version} 替换为所需的版本或使用此标识符定义属性。
回答by Poison
回答by AGan
Basic core implementation (including JPA) Hibernate configurations can be setup using the hibernate-core dependency
基本核心实现(包括 JPA)可以使用 hibernate-core 依赖项设置 Hibernate 配置
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.2.16.Final</version>
</dependency>
and this will transitively pull the following dependencies,
Reference: http://hibernate.org/orm/releases/5.2/