您的位置:首页 > 编程语言 > Java开发

Building Spring 3(Spring3源码导入Eclipse要点)

2011-07-15 20:11 495 查看
注意:本文出自“阿飞”的博客 ,如果要转载本文章,请与作者联系!并注明来源: http://blog.csdn.net/faye0412/article/details/6609521
今天尝试着把从spring svn下载下来的源码导入到eclipse并进行编译(之前是直接从spring下的zip包,导入到工程,编译不通过)。今天Google了一下,发现还是有前辈已经做过类似的事情了,在这里也记录如下,本文主要参考一下博文:官方Spring Team:http://blog.springsource.com/2009/03/03/building-spring-3/iteye上的Blog:/article/3800385.html
步骤类似:一、前提工作(引自iteye作者的博文) ● JDK 使用 Spring 3,至少需要 Java 5;编译 Spring 3,至少需要 Java 6。如果你的机器上装了 N 多个版本的 JDK,请确保环境变量中的那个 JDK 的版本不低于 6.0。
● Ant Ant 1.7 or later。
● 设置 JAVA_OPTS 和 ANT_OPTS 设置环境变量,这依赖于你的机器的配置。要提供 JVM 足够大的内存,否则编译过程中会出现内存溢出。参考设置如下: Config代码 JAVA_OPTS=-Xms512m -Xmx1024m -XX:MaxNewSize=512m -XX:MaxPermSize=1024m ANT_OPTS=-Xms256m -Xmx768m -XX:MaxNewSize=256m -XX:MaxPermSize=512m
在以上三点确保的情况下,可以继续下面的操作了,基本上编译不会出现什么问题了。
二、下载Spring3源代码SVN地址:https://src.springframework.org/svn/spring-framework/trunk/
三、用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.springframework.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) Spring 3 的整个工程依赖于 IVY_CACHE 这个环境变量,它其实就是 ant build 时创建的 ivy-cache 目录,这里面都是 Spring 3 所依赖的第三方 jar 包。 在eclipse中 Window -> Preferences -> Java -> Build Path -> Classpath Variables -> New: 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直接查找并下载:http://ebr.springsource.com/repository/app/bundle
如果有研究spring源代码在这个过程中遇到问题的可以留言我们一起讨论、学习:)

本文新浪博客地址:http://blog.sina.com.cn/s/blog_49fd52cf0100r2rn.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: