【01】eclipse导入spring源码

spring现在把源码都托管到了github上,通过spring的官网找到spring framework 项目,然后找到github即可,也可以直接点击下面链接

https://github.com/spring-projects/spring-framework/tree/4.2.x 然后点击 DownloadZIP按钮,下载到自己电脑的相关目录,然后解压文件

很久没有下载spring源码了。下载下来看到项目的结构有所改变,现在项目的结构有所不同,spring用Gradle进行打包和继承项目,Gradle集成了Ant Maven的功能,对于不了解它的自己搜索一下即可。

步骤:

1、所需工具

        JDK1.8     gradle,eclipse或者spring提供的eclisep/STS(https://spring.io/tools)

2、windows下项目导入步骤

  •      下载好Gradle之后,配置Gradle的环境变量,系统环境变量中path指向Gradle解压后的bin目录

  •      解压下载好的spring代码

  •      在解压目录中运行 import-into-eclipse.bat文件(这时候出现让输入任意键继续,两次,然后开始下载相关依赖,如果失败,就重复运行这个命令,因为由于是外国网站,有些下载会失败)

  • 有时候会出现以下错误

    The command run will be:
    
        gradlew --no-daemon cleanEclipse :spring-oxm:compileTestJava eclipse -x :ecl
    ipse
    
    Press enter when ready.
    请按任意键继续. . .
    Unrecognized VM option 'MaxMetaspaceSize=1024m'
    Error: Could not create the Java Virtual Machine.
    Error: A fatal exception has occurred. Program will exit.
    
    
    -----------------
    这是因为MaxMetaspaceSize=1024m 这个属性jvm不认识,这时候可以修改下载下的源码的gradlew.bat 文件,把MaxMetaspaceSize=1024m这一行给删除掉
    然后重新运行import-into-eclipse.bat
    ----------------------
    修正一下,上面解决方案是错误的。这是因为MaxMetaspaceSize 这个是jdk8中新增加的jvm配置,用于取代永久代设置(XX:MaxPermSize)
    所以上述错误是jdk版本不对所导致,
    可以在gradlew.bat 文件中把jdk的版本打印出来
    set DIRNAME=%~dp0
    if "%DIRNAME%" == "" set DIRNAME=.
    set APP_BASE_NAME=%~n0
    set APP_HOME=%DIRNAME%
    
    echo ERROR:XXXXXXXXXXXXXXXXXXXXX  %JAVA_HOME%/bin/java.exe.
    
    例如XXXX这边。这样查看是否是jdk8
    

     

  • 完成以后会出现以下画面

135327_4vlw_2457218.png

  •      这个步骤完成以后,然后点击任意键继续,这时候会提示如何把代码按照提示导入到STS中(打开eclipse-sts,cmd窗口暂时不要动)

  • 按照提示导入完成以后,在eclipse-sts中会有如显示

    135514_TnIc_2457218.png

  • 然后回到cmd窗口,按照提示完成剩余步骤即可

  • 这样我们就能开始愉快的spring源码研究之旅啦

     

我把cmd窗口中的完整输出显示出来如下:

D:\open-source\spring-framework-4.2.x-e\spring-framework-4.2.x>import-into-eclipse.bat


-----------------------------------------------------------------------
Spring Framework Eclipse/STS project import guide

This script will guide you through the process of importing the
Spring Framework sources into Eclipse/STS. It is recommended that you
have a recent version of the SpringSource Tool Suite (this script has
been tested against STS '2.9.2.RELEASE'), but at the minimum you will
need Eclipse + AJDT.

If you need to download and install STS, please do that now by
visiting http://spring.io/tools/sts/all

Otherwise, press enter and we'll begin.
请按任意键继续. . .

-----------------------------------------------------------------------
STEP 1: Generate subproject Eclipse metadata

The first step will be to generate Eclipse project metadata for each
of the spring-* subprojects. This happens via the built-in
"Gradle wrapper" script (./gradlew in this directory). If this is your
first time using the Gradle wrapper, this step may take a few minutes
while a Gradle distribution is downloaded for you.

The command run will be:

    gradlew cleanEclipse :spring-oxm:compileTestJava eclipse -x :eclipse

Press enter when ready.
请按任意键继续. . .
Downloading https://services.gradle.org/distributions/gradle-1.12-all.zip
:spring-websocket:eclipseProject
:spring-websocket:eclipseSettings
:spring-websocket:eclipseWstComponent
:spring-websocket:eclipse

BUILD SUCCESSFUL

Total time: 23 mins 28.768 secs

-----------------------------------------------------------------------
STEP 2: Import subprojects into Eclipse/STS

Within Eclipse/STS, do the following:

File > Import... > Existing Projects into Workspace
     > When prompted for the 'root directory', provide D:\open-source\spring-fra
mework-4.2.x-e\spring-framework-4.2.x\
     > 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.

When the above is complete, return here and press the enter key.
请按任意键继续. . .

-----------------------------------------------------------------------
STEP 3: generate root project Eclipse metadata

Unfortunately, Eclipse does not allow for importing project
hierarchies, so we had to skip root project metadata generation in the
during step 1. In this step we simply generate root project metadata
so you can import it in the next step.

The command run will be:

    gradlew :eclipse

Press the enter key when ready.
请按任意键继续. . .
: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
:eclipseClasspath
:eclipseJdtPrepare
:eclipseJdt
:eclipseProject
:eclipseSettings
:eclipseWstComponent
:eclipse

BUILD SUCCESSFUL

Total time: 53.201 secs

-----------------------------------------------------------------------
STEP 4: Import root project into Eclipse/STS

Follow the project import steps listed in step 2 above to import the
root project.

Press enter when complete, and move on to the final step.
请按任意键继续. . .

-----------------------------------------------------------------------
STEP 5: Enable Git support for all projects

- In the Eclipse/STS Package Explorer, select all spring* projects.
- Right-click to open the context menu and select Team > Share Project...
- In the Share Project dialog that appears, select Git and press Next
- Check "Use or create repository in parent folder of project"
- Click Finish

When complete, you'll have Git support enabled for all projects.

You're ready to code! Goodbye!

 

 

转载于:https://my.oschina.net/u/2457218/blog/617604

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值