前言:写这篇博客的初衷是使用Maven构建三大框架(Spring、Hibernate、Struts2),而这些框架都不是单独的一个包,他们包含很多模块,也依赖了大量的第三方JAR包,而且也有交叉依赖(共同的依赖),在这里进行一个整理。我初步打算是在前面对这些进行简单的解释,在最后整体制作一个POM,这个POM是用来聚合项目的顶级配置,所有该项目的模块都依赖这个POM。
为了简述各组件之间的依赖,在此做一下约定:A -> B 表示A依赖于B
在此声明我解析的SSH版本(因版本之间有些差异):
- hibernate-release-5.1.0.Final
- spring-framework-4.2.5.RELEASE-dist
- struts-2.3.32-all
一、Hibernate
1.1 The Hibernate Modules/Artifacts
Hibernate’s functionality(功能) is split into a number of modules/artifacts meant to isolate dependencies (modularity模块化).
- hibernate-core:The main (core) Hibernate module. Defines its ORM features and APIs as well as the various integration SPIs.(定义了ORM的特性以及各种集成的SPI接口。)
- hibernate-entitymanager:Defines Hibernate’s support for JPA(定义了Hibernate对JPA的支持)
- hibernate-java8:Support for using Java8 specific data-types such as any of the JSR 310 Date/Time types in domain model.(支持使用Java8特定数据类型)
- hibernate-envers:Hibernate’s historical entity versioning feature
- hibernate-spatial:Hibernate’s Spatial/GIS data-type support
- hibernate-osgi:Hibernate support for running in OSGi containers.
- hibernate-c3p0:Integrates the C3P0 connection pooling library into Hibernate(将C3P0数据库连接池集成到Hibernate)
- hibernate-hikaricp:Integrates the HikariCP connection pooling library into Hibernate(将HikariCP数据库连接池集成到Hibernate)
- hibernate-proxool:Integrates the Proxool connection pooling library into Hibernate(将Proxool数据库连接池集成到Hibernate)
- hibernate-ehcache:Integrates the Ehcache caching library into Hibernate as a second-level cache provider.(将Ehcache缓存库作为二级缓存集成到Hibernate)
- hibernate-infinispan:Integrates the Infinispan caching library into Hibernate as a second-level cache provider.(将Infinispan缓存库作为二级缓存集成到Hibernate)
1.2 Release Bundle Downloads
The Hibernate team provides release bundles hosted on the SourceForge File Release System, in bothTGZ andZIP formats. Each release bundle contains JAR files, documentation, source code, and other goodness.
You can download releases of Hibernate, in your chosen format, from the list athttps://sourceforge.net/projects/hibernate/files/hibernate-orm/ The release bundle is structured as follows:
- The lib/required/ directory contains the hibernate-core jar and all of its dependencies. All of these jars are required to be available on your classpath no matter which features of Hibernate are being used.(无论使用Hibernate的哪种特性,这个文件夹中的jar包都是必须)
- The /lib/jpa/ directory contains the hibernate-entitymanager jar as well as all of its dependencies (beyond those in lib/required/)
- The lib/java8/ directory contains the hibernate-java8 jar and all of its dependencies (beyond those in lib/required/)
- The lib/envers directory contains the hibernate-envers jar and all of its dependencies (beyond those in lib/required/ and lib/jpa/).
- The lib/spatial/ directory contains the hibernate-spatial jar and all of its dependencies (beyond those in lib/required/)
- The lib/osgi/ directory contains the hibernate-osgi jar and all of its dependencies (beyond those in lib/required/ and lib/jpa/)
- The lib/optional/ directory contains the jars needed for the various connection pooling and second-level cache integrations provided by Hibernate, along with their dependencies.(该包包含了由Hibernate提供的各种连接池和二级缓存的集成包,以及他们的依赖)
1.2.1 required文件夹
该包中核心是hibernate-core-*.Final.jar,该包中包含了十个文件,我们查看hibernate-core包的POM中的依赖如下:
<dependencies>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
<version>3.3.0.Final</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.20.0-GA</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>antlr</groupId>
<artifactId>antlr</artifactId>
<version>2.7.7</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.transaction</groupId>
<artifactId>jboss-transaction-api_1.2_spec</artifactId>
<version>1.0.1.Final</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jandex</artifactId>
<version>2.0.3.Final</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.fasterxml</groupId>
<artifactId>classmate</artifactId>
<version>1.3.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<artifactId>*</artifactId>
<groupId>*</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hibernate.common</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<version>5.0.1.Final</version>
<scope>compile</scope>
</dependency>
</dependencies>
<name>Core Hibernate O/RM functionality</name>
<description>
The core O/RM functionality as provided by Hibernate
</description>
不难发现,这些依赖就是required文件夹下,除了hibernate-core-*.Final.jar文件的所有其它文件,因为hibernate-core的POM中依赖已经定义了这些,所以我们只需要在项目的依赖中写上hibernate-core依赖即可,换句话说:我们利用Maven导入Hibernate的核心依赖的时候,只需要依赖hibernate-core-*.Final.jar即可,如下:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.1.0.Final</version>
</dependency>
只要导入这个依赖,由于传递性依赖,就会自然而然的导入上面的那九个依赖文件,依赖关系图:
1.2.2 jpa文件夹
该包中只包含了hibernate-entitymanager-*.Final.jar,我们查看其POM中的依赖如下:
<dependencies>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
<version>3.3.0.Final</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.1.0.Final</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<artifactId>*</artifactId>
<groupId>*</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hibernate.common</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<version>5.0.1.Final</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.1-api</artifactId>
<version>1.0.0.Final</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.20.0-GA</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.6.6</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.transaction</groupId>
<artifactId>jboss-transaction-api_1.2_spec</artifactId>
<version>1.0.1.Final</version>
<scope>compile</scope>
</dependency>
</dependencies>
<name>(deprecated - use hibernate-core instead) Hibernate JPA Support</name>
<description>(deprecated - use hibernate-core instead) Hibernate O/RM implementation of the JPA specification</description>
不知你注意到没有,其大部分依赖与hibernate-core相同,而且它还依赖hibernate-core,但是上面的描述信息写的很详细——不赞成使用并使用hibernate-core进行代替。这部分的依赖关系就不在画出来了,没必要。
1.2.3 jpa-metamodel-generator文件夹
该包中只包含了hibernate-jpamodelgen-*.Final.jar,我们查看其POM中的依赖如下:
<dependencies>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
<version>3.3.0.Final</version>
<scope>compile</scope>
</dependency>
</dependencies>
<name>Hibernate JPA 2 Metamodel Generator</name>
<description>Annotation Processor to generate JPA 2 static metamodel classes</description>
依赖关系非常简单,只依赖与jboss-logging,并且jboss-logging也是hibernate-core的依赖之一,描述信息表示该文件是:生成JPA 2静态模型类的注解处理器。
1.2.4 java8文件夹
该包中只包含了hibernate-java8-*.Final.jar,我们查看其POM中的依赖如下:
<dependencies>
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
<version>3.3.0.Final</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.hibernate&