学习Hibernate源码一_下载hibernate源码并编译为eclipse项目

学习Hibernate源码一

1.下载hibernate源码,并构建起eclipse项目

1hibernate的源代码采用git管理,安装git客户端以后,通过点击https://github.com/hibernate/hibernate-orm页面右侧的“Clone in Desktop”可启动客户端将代码clone到本地。当然也可以直接使用

git clone git://github.com/hibernate/hibernate-orm.git

命令下载代码。

下载完毕后,打开根目录下的readme文件,可以看到详细的把源代码构建为不同IDE项目的说明;以及其他的一些信息。

对应文档的网站链接:

https://community.jboss.org/wiki/BuildingHibernateORM4x5x

构建IDE部分:

Eclipse

To create the Eclipse project files you can run

./gradlew eclipse

After changes to the dependencies you need to clean the project files and recreate them:

./gradlew cleanEclipse eclipse

 

See also  Contributing to Hibernate using Eclipse

Idea

To create the Idea project files you can run

./gradlew idea

After changes to the dependencies you need to clean the project files and recreate them:

./gradlew cleanIdea idea

此处的gradlehibernate所使用的自动构建工具,官网地址为:

http://www.gradle.org/

下载地址为:http://www.gradle.org/downloads,选择一个版本进行下载

此处是Hibernate团队阐述其从Maven迁移到Gradle的原因:https://community.jboss.org/wiki/GradleWhy

至于grable,有时间会深入学习一下,感兴趣的同学可以看看这位博主的博客:

http://www.blogjava.net/wldandan/archive/2012/06/26/381532.html

言归正传,下载grable后,解压,我将其解压到了C盘根目录,解压完毕的grable所在目录为:C:\gradle-1.7,将其子目录C:\gradle-1.7\bin目录加入系统的Path变量

编译代码为eclipse项目:

1)进入hibernate源码的根目录:

cd C:\Users\Administrator\Documents\GitHub\hibernate-orm

2)执行gradlew.bat eclipse

接着会自动下载项目所需要的依赖项,具体输出如下:

C:\Users\Administrator\Documents\GitHub\hibernate-orm>gradlew.bat eclipse

Creating properties on demand (a.k.a. dynamic properties) has been deprecated and is scheduled to be removed in Gradle 2.0. Please read http://gradle.org/docs/current/dsl/org.gradle.api.plugins.ExtraPropertiesExtension.html for information on

Deprecated dynamic property: "exportPackageVersion" on "project ':documentation'", value: "4.3.0".

Deprecated dynamic property "exportPackageVersion" created in multiple locations.

FAILURE: Build failed with an exception.

* Where:

Build file 'C:\Users\Administrator\Documents\GitHub\hibernate-orm\build.gradle' line: 85

* What went wrong:

A problem occurred evaluating root project 'hibernate-orm'.

> org/hibernate/build/gradle/publish/auth/maven/AuthenticationManager : Unsupported major.minor version 51.0

* Try:

Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

此时我去查看我的环境变量,JAVA_HOME指向的是64位的JDK6,将其指向32JDK7后再次执行

gradlew.bat eclipse

发现此时gradlew又去下载了其他的依赖包,查看hibernate-rom目录下的libraries.gradle文件,可以看到hibernate的依赖包。

重新编译过程中还是报错了,具体错误:

:hibernate-core:compileJava

警告: [options] 未与 -source 1.6 一起设置引导类路径

C:\Users\Administrator\Documents\GitHub\hibernate-orm\hibernate-core\src\main\java\org\hibernate\annotations\Loader.java:38: 错误: 编码GBK的不可映射字符

 * @author L锟絪zl?Benke

                 ^

C:\Users\Administrator\Documents\GitHub\hibernate-orm\hibernate-core\src\main\java\org\hibernate\annotations\ResultCheckStyle.java:29: 错误: 编码GBK的不可映射字符

 * @author L锟絪zl?Benke

                 ^

C:\Users\Administrator\Documents\GitHub\hibernate-orm\hibernate-core\src\main\java\org\hibernate\annotations\SQLDelete.java:37: 错误: 编码GBK的不可映射字符

 * @author L锟絪zl?Benke

                 ^

C:\Users\Administrator\Documents\GitHub\hibernate-orm\hibernate-core\src\main\java\org\hibernate\annotations\SQLDeleteAll.java:37: 错误: 编码GBK的不可映射字符

 * @author L锟絪zl?Benke

                 ^

C:\Users\Administrator\Documents\GitHub\hibernate-orm\hibernate-core\src\main\java\org\hibernate\annotations\SQLInsert.java:37: 错误: 编码GBK的不可映射字符

 * @author L锟絪zl?Benke

                 ^

C:\Users\Administrator\Documents\GitHub\hibernate-orm\hibernate-core\src\main\java\org\hibernate\annotations\SQLUpdate.java:37: 错误: 编码GBK的不可映射字符

 * @author L锟絪zl?Benke

                 ^

: 某些输入文件使用或覆盖了已过时的 API

: 有关详细信息, 请使用 -Xlint:deprecation 重新编译。

: 某些输入文件使用了未经检查或不安全的操作。

: 有关详细信息, 请使用 -Xlint:unchecked 重新编译。

1 个警告

google了一下,貌似是区域语言设置的问题,需要修改为“英语(英国)”,但编译并没用中断,接着编译。我将控制面板中的区域语言设置修改后,继续观察,看其是否还会报同样的错误。

最终还是失败了:

:hibernate-entitymanager:compileJava

警告: [options] 未与 -source 1.6 一起设置引导类路径

C:\Users\Administrator\Documents\GitHub\hibernate-orm\hibernate-entitymanager\src\main\java\org\hibernate\jpa\AvailableSettings.java:290: 错误: 编码GBK的不可映射字符

         * contains 鈥淐REATE SCHEMA?commands.  If this property is not supplied (or is explicitly {@code false}), the

                                   ^

: 某些输入文件使用或覆盖了已过时的 API

: 有关详细信息, 请使用 -Xlint:deprecation 重新编译。

: 某些输入文件使用了未经检查或不安全的操作。

: 有关详细信息, 请使用 -Xlint:unchecked 重新编译。

1 个警告

:hibernate-entitymanager:processResources

:hibernate-entitymanager:classes

:hibernate-testing:generateMainLoggingClasses

Download http://repo1.maven.org/maven2/com/experlog/xapool/1.5.0/xapool-1.5.0.jar

Download http://repo1.maven.org/maven2/org/jboss/jbossts/jbossjta/4.16.4.Final/jbossjta-4.16.4.Final.jar

:hibernate-testing:compileJava

警告: [options] 未与 -source 1.6 一起设置引导类路径

: 某些输入文件使用或覆盖了已过时的 API

: 有关详细信息, 请使用 -Xlint:deprecation 重新编译。

: 某些输入文件使用了未经检查或不安全的操作。

: 有关详细信息, 请使用 -Xlint:unchecked 重新编译。

1 个警告

:hibernate-testing:processResources UP-TO-DATE

:hibernate-testing:classes

:hibernate-testing:jar

:hibernate-entitymanager:generateTestJpaMetamodelClasses

此处略去部分download信息

Download http://repo1.maven.org/maven2/org/jboss/shrinkwrap/shrinkwrap-build/1.0.0-alpha-11/shrinkwrap-build-1.0.0-alpha-11.pom

 

FAILURE: Build failed with an exception.

 

* What went wrong:

Could not resolve all dependencies for configuration ':hibernate-entitymanager:testCompile'.

> Could not resolve org.jboss.arquillian:arquillian-api:1.0.0.Alpha4.

  Required by:

      org.hibernate:hibernate-entitymanager:4.3.0-SNAPSHOT > org.jboss.weld.arquillian.container:arquillian-weld-ee-embedded-1.1:1.1.2.Final > org.jboss.arquillian:arquillian-spi:1.0.0.Alpha4

   > Could not GET 'http://repository.jboss.org/nexus/content/groups/public/org/jboss/arquillian/arquillian-api/1.0.0.Alpha4/arquillian-api-1.0.0.Alpha4.pom'.

      > The target server failed to respond

 

* Try:

Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 20 mins 17.755 secs

猜测还是和区域和语言有关,因为之前已经在控制面板修改过,重新进入hibernate-rom根目录执行gradlew.bat eclipse再次尝试编译。

又是一堆download信息后,编译开始,盯着编译的命令窗口的输出,关注其是否还会因为编码报错。

:hibernate-osgi:eclipseJdt

:hibernate-osgi:eclipseProject

:hibernate-osgi:eclipse

:hibernate-proxool:generateMainLoggingClasses

Download http://repo1.maven.org/maven2/proxool/proxool/0.8.3/proxool-0.8.3.pom

Download http://repo1.maven.org/maven2/proxool/proxool/0.8.3/proxool-0.8.3.jar

:hibernate-proxool:generateSources

:hibernate-proxool:eclipseClasspath

:hibernate-proxool:eclipseJdt

:hibernate-proxool:eclipseProject

:hibernate-proxool:eclipse

:hibernate-testing:generateSources UP-TO-DATE

:hibernate-testing:eclipseClasspath

Download http://repo1.maven.org/maven2/org/jboss/jbossts/jbossjta/4.16.4.Final/jbossjta-4.16.4.Final-sources.jar

Download http://repo1.maven.org/maven2/com/experlog/xapool/1.5.0/xapool-1.5.0-sources.jar

:hibernate-testing:eclipseJdt

:hibernate-testing:eclipseProject

:hibernate-testing:eclipse

:release:eclipseProject

:release:eclipse

 

BUILD SUCCESSFUL

 

Total time: 9 mins 13.742 secs

最终,编译成功了。

总结:

1)编译需要使用JDK7,估计Hibernate中使用了JDK7的新特性,应该是关于try-rource的使用会比较多,接下来需要从源代码中找一下证据。

2)需要将区域和语言修改为“英语(英国)”。

3)编译时需要联网下载依赖项,因此网速会影响最终的编译时间。

编译完毕后导入项目到eclipse之前,先修改一下JAVA_HOME,需要和你的eclipse的版本一致,否则eclipse无法正常启动。

由于项目较多,导入的过程也会比较缓慢。需要耐心等待,如果想尝试修改hibernate源码并编译查看效果的话,导入时建议勾选copy projects into workspace,将源码拷到你指定的工作空间。

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值