注意:本文出自“阿飞”的博客 ,如果要转载本文章,请与作者联系!
今天Google了一下,发现还是有前辈已经做过类似的事情了,在这里也记录如下,本文主要参考一下博文:
官方Spring Team:
http://blog.springsource.com/2009/03/03/building-spring-3/
iteye上的Blog:
http://zachary-guo.iteye.com/blog/661839
步骤类似:
一、前提工作(引自iteye作者的博文)
Config代码
JAVA_OPTS=-Xms512m -Xmx1024m -XX:MaxNewSize=512m -XX:MaxPermSize=1024m
ANT_OPTS=-Xms256m -Xmx768m -XX:MaxNewSize=256m -XX:MaxPermSize=512m
二、下载Spring3源代码
三、用ANT编译Spring
使用 ant 来 build,它会通过 ivy 来下载 Spring 3 所依赖的第三方 jar 包。这段时间会持续很久,你可以出去玩一会儿游戏或者睡一会儿,我用的是艾普宽带,尽管是2M,但是进行了无数次之后终于基本(为什么说基本,后面会提到)下载下来了。
这个过程中我出错了好多次,每次都重新编译过。万恶的是有好多jar没有下载下来。。。
我们期待的结果应该是这样的,按照SpringTeam博文中提到的也是如此的:
Command代码
---> cd ${SRC_HOME}/build-spring-framework ---> ant Hava a rest...... [......] BUILD SUCCESSFUL
但是我的每次都是BUILD FAILED...
于是乎重新试了N多次,最后终于到了junit test的时候有一项failed了,如下:
[junit] Testcase: getSystemEnvironment_withAndWithoutSecurityManager(org.spr ingframework.core.env.EnvironmentTests): FAILED
按照Spring Team博客作者对@reddog的回复,我尝试了一下,结果SUCCESS!
@reddog: if you wish to run all the tests, but simply ignore this one, add JUnit's @Ignore annotation to the test method that's failing. If you simply wish to build the Spring JARs locally and skip running all tests, simply run `ant jar`. It will compile and package the jars, but will not run any tests. Keep in mind that if you're trying to populate a local Maven repository, you can run `ant install-maven`. This will compile the code, package the JARs and copy them into the correct locations within your local ~/.m2/repository cache.
我到这步编译完后不进行junit test,执行ant jar,结果成功!呵呵呵
接下来要做的事情就是如何将编译好的Spring 源码导入到Eclipse中:
1. 创建IVY_CACHE环境变量(之前不知道这个变量是在哪里设置的,以为会默认,因此工程中出现了无数红xx)
Path代码
Name=IVY_CACHE Path=${SRC_HOME}/ivy-cache/repository
2. 确保eclipse中installed jre是6.0+:
Window -> Preferences -> Java -> Installed JREs,确保选中的是 Java 6。
3. 将Spring 所有工程导入到Eclipse:
File -> Import -> Existing Projects into workspace,root directory 选择 ${Spring_SRC_HOME}。
到这里,你基本上能看到spring的所有工程到导入到了eclipse中,但是有可能仍然会有!号的错误信息,这个有可能ivy中部分包没下载到,我的情况也是如此的,最后我是手动将所有缺失的jar一个个下载拷贝到另ivy中。
缺失的jar包可以到spring直接查找并下载:
如果有研究spring源代码在这个过程中遇到问题的可以留言我们一起讨论、学习:)