Windows下Spring源码编译

Windows下Spring源码编译

下载源码

spring-framework

编译

  1. Spring README.md 中有编译源码的手册

Build from Source

  1. 编译命令 ./gradlew build spring脚本中会自动下载gradle并且执行剩余的编译动作

编译中的问题

在windows中编译会出现几个问题

  1. 堆内存不足
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':referencePdf'.
GC overhead limit exceeded

GC overhead limit exceeded : 说明GC有98%的时间在处理垃圾回收 需要增加java内存

解决方法
修改gradlew.bat中 GRADLE_OPTS 参数设置(按照个人情况设置,不必要设置这么大)

set GRADLE_OPTS=-XX:MaxMetaspaceSize=2048m -Xmx2048m -XX:MaxHeapSize=1024m %GRADLE_OPTS%
  1. 文件未找到
FAILURE: Build failed with an exception.
* What went wrong:
Failed to capture snapshot of input files for task 'distZip' during up-to-date check.
 java.io.FileNotFoundException: D:\git\spring-framework\build\distributions\spring-framework-4.3.11.BUILD-SNAPSHOT-schema.zip (The system cannot find the file specified)...

linux 和windows 的区别导致查找文件时没有找到spring-framework-4.3.11.BUILD-SNAPSHOT-schema.zip

解决方法
修改build.gradle中的schemaZip方法

task schemaZip(type: Zip) {
        group = "Distribution"
        baseName = "spring-framework"
        classifier = "schema"
        description = "Builds -${classifier} archive containing all " +
            "XSDs for deployment at http://springframework.org/schema."
        duplicatesStrategy 'exclude'
        moduleProjects.each { subproject ->
            def Properties schemas = new Properties();

            subproject.sourceSets.main.resources.find {
                it.path.endsWith("META-INF/spring.schemas")
            }?.withInputStream { schemas.load(it) }

            for (def key : schemas.keySet()) {
                def shortName = key.replaceAll(/http.*schema.(.*).spring-.*/, '$1')
                assert shortName != key
                File xsdFile = subproject.sourceSets.main.resources.find {

                    it.path.endsWith(schemas.get(key))
                }
                assert xsdFile != null
                into (shortName) {
                    from xsdFile.path
                }
            }
        }
    }

替换为

task schemaZip(type: Zip) {
        group = "Distribution"
        baseName = "spring-framework"
        classifier = "schema"
        description = "Builds -${classifier} archive containing all " +
            "XSDs for deployment at http://springframework.org/schema."
        duplicatesStrategy 'exclude'
        moduleProjects.each { subproject ->
            def Properties schemas = new Properties();

            subproject.sourceSets.main.resources.find {
            //这的路径需要改为\\
                it.path.endsWith("META-INF\\spring.schemas")
            }?.withInputStream { schemas.load(it) }

            for (def key : schemas.keySet()) {
                def shortName = key.replaceAll(/http.*schema.(.*).spring-.*/, '$1')
                assert shortName != key
                File xsdFile = subproject.sourceSets.main.resources.find {
                    //这里需要进行路径替换
                    it.path.endsWith(schemas.get(key).replaceAll('\\/','\\\\'))
                }
                assert xsdFile != null
                into (shortName) {
                    from xsdFile.path
                }
            }
        }
    }
  1. test过不去
* What went wrong:
Execution failed for task ':spring-context-support:test'.
There were failing tests. See the report at: file:///D:/git/spring-framework/spring-context-support/build/reports/tests/index.html

打开提示的html发现有几条失败的test, 将提示错误的test中方法忽略或者删除
Alt text
对JasperReportsUtils的test
JasperReportsUtils API介绍是 : 为CSV,HTML,PDF和XLS格式的报告提供了一套便利的方法.
对我们学习Spring源码没有影响

导入eclipse

虽然现在提倡使用idea,但是笔者还是习惯使用eclipse

  1. 转换为eclipse项目命令
    还是Srping提供的手册中
./import-into-eclipse.bat

转换为eclipse项目分5个步骤
1). 提示将要转换的项目需要 Eclipse + AJDT 推荐使用STS
2). 提示转换需要用到Gradle,第一次使用会下载
3). 提示将项目导入eclipse/STS

File > Import... > Existing Projects into Workspace
       > When prompted for the 'root directory', provide %CURRENT_DIR%
       > Press enter. You will see the modules show up under "Projects"
       > All projects should be selected/checked. Click Finish.
       > When the project import is complete, you should have no errors.

4). 生成Spring根目录文件
5). 按照步骤2再次导入根文件
6). 完成,提示连接github(IDE已经自动连接了)

  1. 添加eclipse支持Groovy的插件
    由于源码中有Groovy的文件,需要安装插件
    groovy for eclipse

在Wiki中找到Snapshot Builds,下载自己eclipse版本对应的Groovy插件
groovy for eclipse

最后

至此Spring的源码已经完成编译,可以进行开发及学习
Finish

参考原文 : http://www.jianshu.com/p/9205beaa0fe2

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值