第一步:下载spring最新版
spring官网地址:http://projects.spring.io/spring-framework/
点击projects,进入spring的项目页面,
在该页面中选择spring-framework项目。
spring项目的首页上进入github首页,点击github的图标。
进入spring的github也可以直接通过下面的地址:
spring github地址:https://github.com/spring-projects/spring-framework
选择spring的版本,最新稳定版本是4.1.6,
下载spring源码。
spring源码下载结束之后,解压源码到工作空间,此时的源码是不能导入到eclipse,否则会报很多的红叉叉的,spring的源码是基于gradle构建,直接弄到eclipse中,spring需要的依赖包都不会自动下载,而且,此时的源码项目没有eclipse需要的.classpath和.project文件。
第二步:安装gradle
下载gradle地址:http://gradle.org/downloads/
将下载的gradle解压到指定目录,我的路径是E:\dev\gradle,配置环境变量:
GRADLE_HOME=E:\dev\gradle\gradle-2.4
PATH=%GRADLE_HOME%\bin;
打开cmd,运行命令:gradle -v
第三步:用gradle构建eclipse项目
打开cmd,进入spring解压后的源码目录
在源码根目录下使用gradle cleanidea eclipse会将所有的spring工程转换成eclipse工程,但是会很慢,我们最好一个工程一个工程的调用命令
对整个spring工程转换:
针对单个的spring工程转换,
下面是转换spring-core工程时的日志,会将spring-core依赖的jar都自动下载下来,并生成.project和.classpath文件。
E:\luna\hesper\spring-framework-4.1.6.RELEASE\spring-core>gradle cleanIdea eclipse:buildSrc:compileJava UP-TO-DATE:buildSrc:compileGroovy UP-TO-DATE:buildSrc:processResources UP-TO-DATE:buildSrc:classes UP-TO-DATE:buildSrc:jar UP-TO-DATE:buildSrc:assemble UP-TO-DATE:buildSrc:compileTestJava UP-TO-DATE:buildSrc:compileTestGroovy UP-TO-DATE:buildSrc:processTestResources UP-TO-DATE:buildSrc:testClasses UP-TO-DATE:buildSrc:test UP-TO-DATE:buildSrc:check UP-TO-DATE:buildSrc:build UP-TO-DATE:spring-core:cleanIdeaModule UP-TO-DATE:spring-core:cleanIdea UP-TO-DATE:spring-core:eclipseClasspathDownload https://repo.spring.io/libs-release/commons-codec/commons-codec/1.10/commons-codec-1.10.pomDownload https://repo.spring.io/libs-release/org/apache/commons/commons-parent/35/commons-parent-35.pomDownload https://repo.spring.io/libs-release/org/apache/apache/15/apache-15.pomDownload https://repo.spring.io/libs-release/net/sf/jopt-simple/jopt-simple/4.8/jopt-simple-4.8.pomDownload https://repo.spring.io/libs-release/xmlunit/xmlunit/1.6/xmlunit-1.6.pomDownload https://repo.spring.io/libs-release/org/codehaus/woodstox/woodstox-core-asl/4.4.1/woodstox-core-asl-4.4.1.pomDownload https://repo.spring.io/libs-release/javax/xml/stream/stax-api/1.0-2/stax-api-1.0-2.pomDownload https://repo.spring.io/libs-release/org/codehaus/woodstox/stax2-api/3.1.4/stax2-api-3.1.4.pomDownload https://repo.spring.io/libs-release/commons-codec/commons-codec/1.10/commons-codec-1.10.jarDownload https://repo.spring.io/libs-release/net/sf/jopt-simple/jopt-simple/4.8/jopt-simple-4.8.jarDownload https://repo.spring.io/libs-release/xmlunit/xmlunit/1.6/xmlunit-1.6.jarDownload https://repo.spring.io/libs-release/org/codehaus/woodstox/woodstox-core-asl/4.4.1/woodstox-core-asl-4.4.1.jarDownload https://repo.spring.io/libs-release/javax/xml/stream/stax-api/1.0-2/stax-api-1.0-2.jarDownload https://repo.spring.io/libs-release/org/codehaus/woodstox/stax2-api/3.1.4/stax2-api-3.1.4.jarDownload https://repo.spring.io/libs-release/commons-logging/commons-logging/1.2/commons-logging-1.2-sources.jarDownload https://repo.spring.io/libs-release/commons-codec/commons-codec/1.10/commons-codec-1.10-sources.jarDownload https://repo.spring.io/libs-release/net/sf/jopt-simple/jopt-simple/4.8/jopt-simple-4.8-sources.jarDownload https://repo.spring.io/libs-release/xmlunit/xmlunit/1.6/xmlunit-1.6-sources.jarDownload https://repo.spring.io/libs-release/org/codehaus/woodstox/woodstox-core-asl/4.4.1/woodstox-core-asl-4.4.1-sources.jarDownload https://repo.spring.io/libs-release/javax/xml/stream/stax-api/1.0-2/stax-api-1.0-2-sources.jarDownload https://repo.spring.io/libs-release/org/codehaus/woodstox/stax2-api/3.1.4/stax2-api-3.1.4-sources.jar:spring-core:eclipseJdtPrepare:spring-core:eclipseJdt:spring-core:eclipseProject:spring-core:eclipseSettings:spring-core:eclipseWstComponent:spring-core:eclipseBUILD SUCCESSFULTotal time: 1 mins 19.583 secs我转换的工程:spring-txspring-aopspring-beansspring-beans-groovyspring-contextspring-corespring-expressionspring-instrument
spring项目转换结束之后就可以导入到eclipse中了。
第四步:解决红叉叉
此时如果eclipse中spring工程有感叹号,进入属性发现没有jar包:spring-cglib-repack-3.1.jar和spring-objenesis-repack-2.1.jar在spring-core项目下创建目录build/libs,将缺失的两个jar包复制到该目录,刷新一下工程。如果此时eclipse有红叉叉,进入类里面,发现 java.util.Optional这个类找不到,将编译jdk改为1.8。
此时的spring-beans-groovy工程任然由错误。
eclipse需要安装groovy插件
安装完groovy插件之后,重启eclipse,spring项目就导入成功了。