这哥们写的不错,基本上把能出的情况 都出了!
http://wind-bell27.iteye.com/blog/1969930
http://www.cnblogs.com/xleequ/archive/2013/01/16/2863332.html
官方说明:
https://github.com/spring-projects/spring-framework
先讲基本步骤,如下:
- 去GitHub中下载spring framework的源码,https://github.com/spring-projects/spring-framework/releases
- 下载3.2.X其中的一个版本;
- 安装Gradle软件,官网下载,解压即可,设置GRADLE_HOME,和PATH。
- 命令行中运行gradle -v,检查一下是否正确安装配置;
- 命令行中运行spring framework根目录下的import-into-eclipse.bat
- 连续两次回车,就可以开始自动构建;
- 中间出现停止不前的情况里,按ctrl+c终止,再运行就可以进行下去;
- 过程需要花些时间(几个小时都有可能),视下载各种依赖jar包和dom文件的速度而定;
- 在Eclipse菜单File->import选择General下面的Exsiting projects into workspace,这样就导入完成了。
如果你按上述步骤能一次成功的话,那不仅是你运气,而且RP极高。反正我没有,而且还折腾了好多次才成功能。
问题有以下几个:
- 问题一:spring-framework-4.0.0.M3要用jdk1.8
如果你习愦于什么都下最新版的,那么你肯定想都没想就下了spring-framework-4.0.0.M3,而且又那么不好采,正好没看README,那么问题马上就来了,直接报"-XX:MaxMetaspaceSize=1024m"及"could not create theJava Virtual machine"的错误。
查看build.gradle和gradlew.bat中,可以找出原因:
build.gradle中:
- compileJava {
- sourceCompatibility=1.6
- targetCompatibility=1.6
- }
- compileTestJava {
- sourceCompatibility=1.8
- targetCompatibility=1.8
- }
可以看出这个版本的test代码要求用1.8。
gradlew.bat中
- set GRADLE_OPTS=-XX:MaxMetaspaceSize=1024m -Xmx1024m -XX:MaxHeapSize=256m %GRADLE_OPTS%
其中-XX:MaxMetaspaceSize是1.8的写法。
所以如果下载的是4.0的版本,最好把jdk也升级到1.8,要不就下载一下3.2.x的版本就好了。
- 问题2:在build过程中,出现heap内存溢出情况
错误信息如下:
- FAILURE: Build failed with an exception.
- * What went wrong:
- Execution failed for task ':referencePdf'.
- > GC overhead limit exceeded
- * Try:
- Run with --info or --debug option to get more log output.
- * Exception is:
- org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':referen
- cePdf'.
- at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.ex
- ecuteActions(ExecuteActionsTaskExecuter.java:68)
- at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.ex
- ecute(ExecuteActionsTaskExecuter.java:46)
- at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExec
- uter.execute(PostExecutionAnalysisTaskExecuter.java:34)
- at org.gradle.api.internal.changedetection.CacheLockHandlingTaskExecuter
- $1.run(CacheLockHandlingTaskExecuter.java:34)
- at org.gradle.internal.Factories$1.create(Factories.java:22)
- at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(Def
- aultCacheAccess.java:179)
- at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(Def
- aultCacheAccess.java:232)
- at org.gradle.cache.internal.DefaultPersistentDirectoryStore.longRunning
- Operation(DefaultPersistentDirectoryStore.java:138)
- at org.gradle.api.internal.changedetection.DefaultTaskArtifactStateCache
- Access.longRunningOperation(DefaultTaskArtifactStateCacheAccess.java:83)
- at org.gradle.api.internal.changedetection.CacheLockHandlingTaskExecuter
- .execute(CacheLockHandlingTaskExecuter.java:32)
- at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.exec
- ute(SkipUpToDateTaskExecuter.java:55)
- at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execut
- e(ValidatingTaskExecuter.java:57)
- at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecu
- ter.execute(SkipEmptySourceFilesTaskExecuter.java:41)
- at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter
- .execute(SkipTaskWithNoActionsExecuter.java:51)
- at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execut
- e(SkipOnlyIfTaskExecuter.java:52)
- at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter
- .execute(ExecuteAtMostOnceTaskExecuter.java:42)
- at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailur
- e(AbstractTask.java:247)
- at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.executeTask(De
- faultTaskPlanExecutor.java:52)
- at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.processTask(De
- faultTaskPlanExecutor.java:38)
- at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(Defaul
- tTaskPlanExecutor.java:30)
- at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(Defau
- ltTaskGraphExecuter.java:83)
- at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTask
- ExecutionAction.java:29)
- at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecute
- r.java:61)
- at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExec
- uter.java:23)
- at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecu
- ter.java:67)
- at org.gradle.api.internal.changedetection.TaskCacheLockHandlingBuildExe
- cuter$1.run(TaskCacheLockHandlingBuildExecuter.java:31)
- at org.gradle.internal.Factories$1.create(Factories.java:22)
- at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAcc
- ess.java:124)
- at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAcc
- ess.java:112)
- at org.gradle.cache.internal.DefaultPersistentDirectoryStore.useCache(De
- faultPersistentDirectoryStore.java:130)
- at org.gradle.api.internal.changedetection.DefaultTaskArtifactStateCache
- Access.useCache(DefaultTaskArtifactStateCacheAccess.java:79)
- at org.gradle.api.internal.changedetection.TaskCacheLockHandlingBuildExe
- cuter.execute(TaskCacheLockHandlingBuildExecuter.java:29)
- at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecute
- r.java:61)
- at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExec
- uter.java:23)
- at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecu
- ter.java:67)
- at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildEx
- ecutionAction.java:32)
- at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecute
- r.java:61)
- at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecute
- r.java:54)
- at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(Default
- GradleLauncher.java:158)
- at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradle
- Launcher.java:113)
- at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLaun
- cher.java:81)
- at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.jav
- a:38)
- at org.gradle.launcher.exec.InProcessGradleLauncherActionExecuter.execut
- e(InProcessGradleLauncherActionExecuter.java:39)
- at org.gradle.launcher.exec.InProcessGradleLauncherActionExecuter.execut
- e(InProcessGradleLauncherActionExecuter.java:25)
- at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:50)
- at org.gradle.api.internal.Actions$RunnableActionAdapter.execute(Actions
- .java:137)
- at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.
- execute(CommandLineActionFactory.java:201)
- at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.
- execute(CommandLineActionFactory.java:174)
- at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(
- CommandLineActionFactory.java:170)
- at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(
- CommandLineActionFactory.java:139)
- at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionRep
- ortingAction.java:33)
- at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionRep
- ortingAction.java:22)
- at org.gradle.launcher.Main.doAction(Main.java:48)
- at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
- at org.gradle.launcher.Main.main(Main.java:39)
- at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBoots
- trap.java:50)
- at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.j
- ava:32)
- at org.gradle.launcher.GradleMain.main(GradleMain.java:26)
- at org.gradle.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.ja
- va:33)
- at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:130)
- at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:48)
- Caused by: java.lang.OutOfMemoryError: GC overhead limit exceeded
- at org.apache.fop.area.inline.TextArea.addWord(TextArea.java:68)
- at org.apache.fop.layoutmgr.inline.TextLayoutManager.createTextArea(Text
- LayoutManager.java:483)
- at org.apache.fop.layoutmgr.inline.TextLayoutManager.addAreas(TextLayout
- Manager.java:361)
- at org.apache.fop.layoutmgr.inline.LineLayoutManager.addInlineArea(LineL
- ayoutManager.java:1716)
- at org.apache.fop.layoutmgr.inline.LineLayoutManager.addAreas(LineLayout
- Manager.java:1568)
- at org.apache.fop.layoutmgr.BlockLayoutManager.addAreas(BlockLayoutManag
- er.java:395)
- at org.apache.fop.layoutmgr.BlockLayoutManager.addAreas(BlockLayoutManag
- er.java:395)
- at org.apache.fop.layoutmgr.BlockLayoutManager.addAreas(BlockLayoutManag
- er.java:395)
- at org.apache.fop.layoutmgr.BlockLayoutManager.addAreas(BlockLayoutManag
- er.java:395)
- at org.apache.fop.layoutmgr.AreaAdditionUtil.addAreas(AreaAdditionUtil.j
- ava:121)
- at org.apache.fop.layoutmgr.FlowLayoutManager.addAreas(FlowLayoutManager
- .java:305)
- at org.apache.fop.layoutmgr.PageBreaker.addAreas(PageBreaker.java:241)
- at org.apache.fop.layoutmgr.AbstractBreaker.addAreas(AbstractBreaker.jav
- a:508)
- at org.apache.fop.layoutmgr.AbstractBreaker.addAreas(AbstractBreaker.jav
- a:371)
- at org.apache.fop.layoutmgr.PageBreaker.doPhase3(PageBreaker.java:262)
- at org.apache.fop.layoutmgr.AbstractBreaker.doLayout(AbstractBreaker.jav
- a:346)
- at org.apache.fop.layoutmgr.AbstractBreaker.doLayout(AbstractBreaker.jav
- a:264)
- at org.apache.fop.layoutmgr.PageSequenceLayoutManager.activateLayout(Pag
- eSequenceLayoutManager.java:106)
- at org.apache.fop.area.AreaTreeHandler.endPageSequence(AreaTreeHandler.j
- ava:234)
- at org.apache.fop.fo.pagination.PageSequence.endOfNode(PageSequence.java
- :123)
- at org.apache.fop.fo.FOTreeBuilder$MainFOHandler.endElement(FOTreeBuilde
- r.java:340)
- at org.apache.fop.fo.FOTreeBuilder.endElement(FOTreeBuilder.java:169)
- at org.apache.xalan.transformer.TransformerIdentityImpl.endElement(Trans
- formerIdentityImpl.java:1050)
- at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source
- )
- at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknow
- n Source)
- at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContent
- Dispatcher.dispatch(Unknown Source)
- at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Un
- known Source)
- at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
- at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
- at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
- at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
- at org.apache.xalan.transformer.TransformerIdentityImpl.transform(Transf
- ormerIdentityImpl.java:432)
- BUILD FAILED
那就把gradlew.bat的内存设置调大一点,我做实验时,机器的内存是8G、64位系统,直接使用
set GRADLE_OPTS=-XX:MaxPermSize=2048m -Xmx2048m -XX:MaxHeapSize=1024m %GRADLE_OPTS%
(我下载的是spring-framework-3.2.1.RELEASE版本,jdk1.7)
- 问题3:gradle命令的使用
在spring源码的根目录下,提供gradlew.bat和
import-into-eclipse.bat这两个命令,都可以build源码,但如果使用前者就不会生成eclipse的环境需要的一些文件,如下图所示:
另外,在使用import-into-eclipse.bat这个命令build时,可能会遇到一个问题,错误日志如下:
- FAILURE: Build failed with an exception.
- * What went wrong:
- Execution failed for task ':spring-webmvc-tiles3:eclipseClasspath'.
- > Could not resolve all dependencies for configuration 'detachedConfiguration2'.
- > Module version group:org.springframework, module:spring-webmvc-tiles3, vers
- ion:3.2.1.RELEASE, configuration:detachedConfiguration2 declares a dependency on
- configuration 'runtimeMerge' which is not declared in the module descriptor for
- group:org.springframework, module:spring-web, version:3.2.1.RELEASE
- * Try:
- Run with --stacktrace option to get the stack trace. Run with --info or --debug
- option to get more log output.
从日志中可以看出是在build spring-webmvc-tiles3项目时,生成eclipse的.classpath文件时出错,打开其它正常导入的项目的.classpath看下这个文件包含了哪些信息,如打开spring-aop项目的:
- <?xml version="1.0" encoding="UTF-8"?>
- <classpath>
- <classpathentry kind="output" path="spring-aop/bin/eclipse"/>
- <classpathentry output="bin/main" kind="src" path="src/main/java"/>
- <classpathentry output="bin/main" kind="src" path="src/main/resources"/>
- <classpathentry output="bin/test" kind="src" path="src/test/java"/>
- <classpathentry output="bin/test" kind="src" path="src/test/resources"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER" exported="true"/>
- <classpathentry kind="src" path="/spring-core" exported="true"/>
- <classpathentry kind="src" path="/spring-beans" exported="true"/>
- <classpathentry sourcepath="C:/Users/so/.gradle/caches/artifacts-15/filestore/aopalliance/aopalliance/1.0/source/4a4b6d692e17846a9f3da036438a7ac491d3c814/aopalliance-1.0-sources.jar" kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/aopalliance/aopalliance/1.0/jar/235ba8b489512805ac13a8f9ea77a1ca5ebe3e8/aopalliance-1.0.jar" exported="true"/>
- <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/com.jamonapi/jamon/2.4/jar/e2ad6f45c2ba72d8fa798b68a5f9b73c9f047756/jamon-2.4.jar"/>
- <classpathentry sourcepath="C:/Users/so/.gradle/caches/artifacts-15/filestore/commons-pool/commons-pool/1.5.3/source/7c4d461b6574f056e1d4fc6daa16821382b53bef/commons-pool-1.5.3-sources.jar" kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/commons-pool/commons-pool/1.5.3/jar/7ad440d63c6eea5e79f1737e264810c76258d042/commons-pool-1.5.3.jar"/>
- <classpathentry sourcepath="C:/Users/so/.gradle/caches/artifacts-15/filestore/org.aspectj/aspectjweaver/1.7.1/source/5bfa1ea3b5653119dcf22a0d675302e0e5a802b1/aspectjweaver-1.7.1-sources.jar" kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/org.aspectj/aspectjweaver/1.7.1/jar/cf8f3ca56739d3bf8a539362e48f180a31f83433/aspectjweaver-1.7.1.jar"/>
- <classpathentry sourcepath="C:/Users/so/.gradle/caches/artifacts-15/filestore/junit/junit/4.11/source/28e0ad201304e4a4abf999ca0570b7cffc352c3c/junit-4.11-sources.jar" kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/junit/junit/4.11/jar/4e031bb61df09069aeb2bffb4019e7a5034a4ee0/junit-4.11.jar"/>
- <classpathentry sourcepath="C:/Users/so/.gradle/caches/artifacts-15/filestore/org.hamcrest/hamcrest-all/1.3/source/47e033b7ab18c5dbd5fe29fc1bd5a40afe028818/hamcrest-all-1.3-sources.jar" kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/org.hamcrest/hamcrest-all/1.3/jar/63a21ebc981131004ad02e0434e799fd7f3a8d5a/hamcrest-all-1.3.jar"/>
- <classpathentry sourcepath="C:/Users/so/.gradle/caches/artifacts-15/filestore/org.mockito/mockito-core/1.9.5/source/46f703fb4266140c544d48a189cb25947eb6333e/mockito-core-1.9.5-sources.jar" kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/org.mockito/mockito-core/1.9.5/jar/c3264abeea62c4d2f367e21484fbb40c7e256393/mockito-core-1.9.5.jar"/>
- <classpathentry sourcepath="C:/Users/so/.gradle/caches/artifacts-15/filestore/org.hamcrest/hamcrest-core/1.3/source/1dc37250fbc78e23a65a67fbbaf71d2e9cbc3c0b/hamcrest-core-1.3-sources.jar" kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/org.hamcrest/hamcrest-core/1.3/jar/42a25dc3219429f0e5d060061f71acb49bf010a0/hamcrest-core-1.3.jar"/>
- <classpathentry sourcepath="C:/Users/so/.gradle/caches/artifacts-15/filestore/org.objenesis/objenesis/1.0/source/b10c90e57b7bb985a7b6a704769428fe5c2a732c/objenesis-1.0-sources.jar" kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/org.objenesis/objenesis/1.0/jar/9b473564e792c2bdf1449da1f0b1b5bff9805704/objenesis-1.0.jar"/>
- <classpathentry kind="lib" path="D:/DevelopTools/spring-framework-3.2.1.RELEASE/spring-core/build/libs/spring-cglib-repack-3.0.jar" exported="true"/>
- </classpath>
而spring-webmvc-tiles3下根本就没有.classpath的影子,没得比较,虽然上面的错误日志的E文都认识,但还是看不出它在讲什么,不过大体能看得出是依赖出了问题,那只能是想办法顺藤摸瓜了。重新打开build.gradle,找到有关spring-webmvc-tiles3项目的描述,如下:
- project("spring-webmvc-tiles3") {
- description = "Spring Framework Tiles3 Integration"
- merge.into = project(":spring-webmvc")
- dependencies {
- provided(project(":spring-context"))
- provided(project(":spring-web"))
- provided("javax.el:el-api:1.0")
- provided("javax.servlet:jstl:1.2")
- provided("javax.servlet.jsp:jsp-api:2.1")
- optional("org.apache.tiles:tiles-request-api:1.0.1")
- optional("org.apache.tiles:tiles-api:3.0.1")
- optional("org.apache.tiles:tiles-core:3.0.1") {
- exclude group: "org.slf4j", module: "jcl-over-slf4j"
- }
- optional("org.apache.tiles:tiles-servlet:3.0.1") {
- exclude group: "org.slf4j", module: "jcl-over-slf4j"
- }
- optional("org.apache.tiles:tiles-jsp:3.0.1") {
- exclude group: "org.slf4j", module: "jcl-over-slf4j"
- }
- optional("org.apache.tiles:tiles-extras:3.0.1") {
- exclude group: "org.slf4j", module: "jcl-over-slf4j"
- }
- optional("org.apache.tiles:tiles-el:3.0.1") {
- exclude group: "org.slf4j", module: "jcl-over-slf4j"
- }
- provided("javax.servlet:javax.servlet-api:3.0.1")
- testCompile("org.slf4j:slf4j-jcl:${slf4jVersion}")
- }
- }
打开C:/Users/so/.gradle/caches/artifacts-15/filestore,挨个依赖进行检查,jar包倒是最下载下来了,但是"org.apache.tiles:tiles-jsp:3.0.1"、"org.apache.tiles:tiles-extras:3.0.1"、"org.apache.tiles:tiles-el:3.0.1"三个却没有下载到source,其它包都有jar、pom、source三个目录,这三个没有source目录,只有jar、pom目录,问题应该是出现在这里。
后来终于让我找到了这么一个东西:http://issues.gradle.org/browse/GRADLE-1157,正好证实我前面的猜想,所以按照issue中的解决办法,在build.gradle中加上如下部分:
- eclipseClasspath {
- downloadSources = false; // required for eclipseClasspath to work
- }
关于spring-webmvc-tiles3项目的脚本、就变成这样了:
- project("spring-webmvc-tiles3") {
- description = "Spring Framework Tiles3 Integration"
- merge.into = project(":spring-webmvc")
- dependencies {
- provided(project(":spring-context"))
- provided(project(":spring-web"))
- provided("javax.el:el-api:1.0")
- provided("javax.servlet:jstl:1.2")
- provided("javax.servlet.jsp:jsp-api:2.1")
- optional("org.apache.tiles:tiles-request-api:1.0.1")
- optional("org.apache.tiles:tiles-api:3.0.1")
- optional("org.apache.tiles:tiles-core:3.0.1") {
- exclude group: "org.slf4j", module: "jcl-over-slf4j"
- }
- optional("org.apache.tiles:tiles-servlet:3.0.1") {
- exclude group: "org.slf4j", module: "jcl-over-slf4j"
- }
- optional("org.apache.tiles:tiles-jsp:3.0.1") {
- exclude group: "org.slf4j", module: "jcl-over-slf4j"
- }
- optional("org.apache.tiles:tiles-extras:3.0.1") {
- exclude group: "org.slf4j", module: "jcl-over-slf4j"
- }
- optional("org.apache.tiles:tiles-el:3.0.1") {
- exclude group: "org.slf4j", module: "jcl-over-slf4j"
- }
- provided("javax.servlet:javax.servlet-api:3.0.1")
- testCompile("org.slf4j:slf4j-jcl:${slf4jVersion}")
- }
- eclipseClasspath {
- downloadSources = false; // required for eclipseClasspath to work
- }
- }
重新运行命令,这一次终于让我看到了BUILD SUCCESSFUL的字样了……
成功build完成后,可以看到spring目录下的spring-webmvc-tiles3项目也正常生成了导入eclipse需要的文件。打开.classpath查看一下:
- <?xml version="1.0" encoding="UTF-8"?>
- <classpath>
- <classpathentry kind="output" path="spring-webmvc-tiles3/bin/eclipse"/>
- <classpathentry output="bin/main" kind="src" path="src/main/java"/>
- <classpathentry output="bin/test" kind="src" path="src/test/java"/>
- <classpathentry output="bin/test" kind="src" path="src/test/resources"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER" exported="true"/>
- <classpathentry kind="src" path="/spring-context" exported="true"/>
- <classpathentry kind="src" path="/spring-web" exported="true"/>
- <classpathentry kind="src" path="/spring-webmvc" exported="true"/>
- <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/org.apache.tiles/tiles-request-api/1.0.1/jar/ac444f7d599a6ae28c360cd10fdf2aafa3b87106/tiles-request-api-1.0.1.jar"/>
- <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/org.apache.tiles/tiles-api/3.0.1/jar/3d49cebe1adfb2074332ccb16eb9cfe7647e1759/tiles-api-3.0.1.jar"/>
- <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/org.apache.tiles/tiles-core/3.0.1/jar/359a3c7f0155f03ae5d12d2f779859a453c437bf/tiles-core-3.0.1.jar"/>
- <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/org.apache.tiles/tiles-servlet/3.0.1/jar/4ec5bed5f984ac1ed54bec1cbb0e51c1cb4e3dad/tiles-servlet-3.0.1.jar"/>
- <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/org.apache.tiles/tiles-jsp/3.0.1/jar/3554582e83bd84bcce601b935440ff281d1d210f/tiles-jsp-3.0.1.jar"/>
- <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/org.apache.tiles/tiles-extras/3.0.1/jar/2b959bcc00256131e6f9c8b44da0e8937cb1b8ac/tiles-extras-3.0.1.jar"/>
- <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/org.apache.tiles/tiles-el/3.0.1/jar/e3454acc31fcb2705e7c82cffe69b9b14a9dde46/tiles-el-3.0.1.jar"/>
- <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/javax.el/el-api/1.0/jar/df8c6ce0406676e70c5d018e5fb988be1bcf1024/el-api-1.0.jar"/>
- <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/javax.servlet/jstl/1.2/jar/74aca283cd4f4b4f3e425f5820cda58f44409547/jstl-1.2.jar"/>
- <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/javax.servlet.jsp/jsp-api/2.1/jar/63f943103f250ef1f3a4d5e94d145a0f961f5316/jsp-api-2.1.jar"/>
- <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/javax.servlet/javax.servlet-api/3.0.1/jar/6bf0ebb7efd993e222fc1112377b5e92a13b38dd/javax.servlet-api-3.0.1.jar"/>
- <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/junit/junit/4.11/jar/4e031bb61df09069aeb2bffb4019e7a5034a4ee0/junit-4.11.jar"/>
- <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/org.hamcrest/hamcrest-all/1.3/jar/63a21ebc981131004ad02e0434e799fd7f3a8d5a/hamcrest-all-1.3.jar"/>
- <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/org.mockito/mockito-core/1.9.5/jar/c3264abeea62c4d2f367e21484fbb40c7e256393/mockito-core-1.9.5.jar"/>
- <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/org.easymock/easymock/2.5.2/jar/e25783424f37ade86d387afbdbb7845a6782ef1e/easymock-2.5.2.jar"/>
- <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/org.easymock/easymockclassextension/2.5.2/jar/59ee00208cca7b869b661d78aed67cc5bc0db804/easymockclassextension-2.5.2.jar"/>
- <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/org.slf4j/slf4j-jcl/1.6.1/jar/b5902b1ba8ec58a96140bb7445037b3512cc99bb/slf4j-jcl-1.6.1.jar"/>
- <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/commons-beanutils/commons-beanutils/1.8.0/jar/c651d5103c649c12b20d53731643e5fffceb536/commons-beanutils-1.8.0.jar"/>
- <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/commons-digester/commons-digester/2.0/jar/3dbd8a76683cd563583a2c78c356ad8b8acf38bf/commons-digester-2.0.jar"/>
- <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/org.apache.tiles/tiles-request-servlet/1.0.1/jar/b74ca6c9c9eedfcaf1b8e9a8889d0dcf615df33d/tiles-request-servlet-1.0.1.jar"/>
- <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/org.apache.tiles/tiles-autotag-core-runtime/1.1.0/jar/1fb6109d5bc35c7403a55d019e0e8cf8ec06b49e/tiles-autotag-core-runtime-1.1.0.jar"/>
- <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/org.apache.tiles/tiles-template/3.0.1/jar/e9ab8acfa97bc812a71334394d1f573b25b5aebe/tiles-template-3.0.1.jar"/>
- <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/org.apache.tiles/tiles-request-jsp/1.0.1/jar/ad5fa55a948087e67593adbff312206d07033c08/tiles-request-jsp-1.0.1.jar"/>
- <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/commons-logging/commons-logging/1.1.1/jar/5043bfebc3db072ed80fbd362e7caf00e885d8ae/commons-logging-1.1.1.jar"/>
- <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/aopalliance/aopalliance/1.0/jar/235ba8b489512805ac13a8f9ea77a1ca5ebe3e8/aopalliance-1.0.jar"/>
- <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/org.apache.tiles/tiles-request-servlet-wildcard/1.0.1/jar/b84cc2ad3647ec2c4e172803719277e74bde4b3f/tiles-request-servlet-wildcard-1.0.1.jar"/>
- <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/org.codehaus.jackson/jackson-core-asl/1.5.2/jar/d31b0bc93ebc95c6aa0cdb1b044701ba17429d78/jackson-core-asl-1.5.2.jar"/>
- <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/org.codehaus.jackson/jackson-mapper-asl/1.5.2/jar/5d242931f6a8baa486ef8646ec8476cf6a14b50/jackson-mapper-asl-1.5.2.jar"/>
- <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/com.google.guava/guava/r09/jar/9c8991d491d714053d300de0f8657d95780ff923/guava-r09.jar"/>
- <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/com.github.spullara.mustache.java/core/0.6.2/jar/88ee806dd40a1e836d3dc1ac6ba8487ccd0ac693/core-0.6.2.jar"/>
- <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/com.github.spullara.mustache.java/builder/0.6.2/jar/79a18555b1948b81bc94fe570f8d8a3c6fe2966c/builder-0.6.2.jar"/>
- <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/org.apache.tiles/tiles-request-mustache/1.0.1/jar/4fff86a848e8a10d0e59c2058dad1aba07c21c2e/tiles-request-mustache-1.0.1.jar"/>
- <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/org.freemarker/freemarker/2.3.15/jar/c8cfe522476fcec8da5c980d58bf62d6ab0cf27c/freemarker-2.3.15.jar"/>
- <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/org.apache.tiles/tiles-request-freemarker/1.0.1/jar/9b5709d70ac5c80586fdbb6ddf11577d97492582/tiles-request-freemarker-1.0.1.jar"/>
- <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/org.apache.tiles/tiles-freemarker/3.0.1/jar/a452de79623f48bbd642073424faa9e46eed2c79/tiles-freemarker-3.0.1.jar"/>
- <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/oro/oro/2.0.8/jar/5592374f834645c4ae250f4c9fbb314c9369d698/oro-2.0.8.jar"/>
- <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/commons-lang/commons-lang/2.4/jar/16313e02a793435009f1e458fa4af5d879f6fb11/commons-lang-2.4.jar"/>
- <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/commons-collections/commons-collections/3.2.1/jar/761ea405b9b37ced573d2df0d1e3a4e0f9edc668/commons-collections-3.2.1.jar"/>
- <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/org.apache.velocity/velocity/1.6.2/jar/1b470ec12a9b8aa69b0458a7e477dacb2cbdd6a0/velocity-1.6.2.jar"/>
- <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/org.apache.velocity/velocity-tools/2.0/jar/69936384de86857018b023a8c56ae0635c56b6a0/velocity-tools-2.0.jar"/>
- <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/org.apache.tiles/tiles-request-velocity/1.0.1/jar/5b1532240d5a69244c468e38c89158caff29f3ce/tiles-request-velocity-1.0.1.jar"/>
- <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/org.apache.tiles/tiles-velocity/3.0.1/jar/3ff74e88c4a6fe4e70e89492acf0c2c235659eac/tiles-velocity-3.0.1.jar"/>
- <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/org.mvel/mvel2/2.0.11/jar/14bb21dabd899d2e60d9c0d008f267ed0d6c9ea8/mvel2-2.0.11.jar"/>
- <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/org.apache.tiles/tiles-mvel/3.0.1/jar/582c704beb37b6be8370e5f068f92f5c1afd1814/tiles-mvel-3.0.1.jar"/>
- <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/jboss/javassist/3.7.ga/jar/6d271a67a1d8718bfb225ace5a25f1c09427c9f8/javassist-3.7.ga.jar"/>
- <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/ognl/ognl/2.7.3/jar/8c391fdc943b352045bd35c4f57306ccc6442f7c/ognl-2.7.3.jar"/>
- <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/org.apache.tiles/tiles-ognl/3.0.1/jar/8388c282fa8e0013814cd2bba43e5cf3bcde23f0/tiles-ognl-3.0.1.jar"/>
- <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/org.apache.tiles/tiles-compat/3.0.1/jar/c740c6ab329bacaae02863723280eadead778edc/tiles-compat-3.0.1.jar"/>
- <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/org.hamcrest/hamcrest-core/1.3/jar/42a25dc3219429f0e5d060061f71acb49bf010a0/hamcrest-core-1.3.jar"/>
- <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/org.objenesis/objenesis/1.2/jar/bfcb0539a071a4c5a30690388903ac48c0667f2a/objenesis-1.2.jar"/>
- <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/cglib/cglib-nodep/2.2/jar/59afed7ab65e7ec6585d5bc60556c3cbd203532b/cglib-nodep-2.2.jar"/>
- <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/org.slf4j/slf4j-api/1.6.1/jar/6f3b8a24bf970f17289b234284c94f43eb42f0e4/slf4j-api-1.6.1.jar"/>
- <classpathentry kind="src" path="/spring-aop" exported="true"/>
- <classpathentry kind="src" path="/spring-core" exported="true"/>
- <classpathentry kind="src" path="/spring-beans" exported="true"/>
- <classpathentry kind="src" path="/spring-expression" exported="true"/>
- <classpathentry kind="src" path="/spring-instrument" exported="true"/>
- <classpathentry kind="src" path="/spring-oxm" exported="true"/>
- <classpathentry kind="src" path="/spring-context-support" exported="true"/>
- <classpathentry kind="src" path="/spring-jdbc" exported="true"/>
- <classpathentry kind="src" path="/spring-tx" exported="true"/>
- </classpath>
果然没有sourcepath的信息。
折腾了那么久,终于到了可以看一下成果的时候了。
Spring Tool Suite说简单一点就是Spring家的eclipse,去官网下一个最新版,安装上。
打开STS,菜单File->import选择General下面的Exsiting projects into workspace,勾选要导入的子项目,确定即可。
成果如上,齐齐整整,没有错误,挺好!
亲测成功
spring3.2通过新的基于Gradle的构建来构建项目,它取代了之前的Ant+Ivy系统。
本文就介绍如何将spring3.2的源码导入到myeclipse中。
大伙可先参考一下spring的官方文档说明:https://github.com/SpringSource/spring-framework
Building from source
The Spring Framework uses a Gradle-based build system. In the instructions below, ./gradlew is invoked from the root of the source tree and serves as a cross-platform, self-contained bootstrap mechanism for the build. The only prerequisites are Git and JDK 1.7+.(先决条件是Git和JDK 1.7+)
check out sources
git clone git://github.com/SpringSource/spring-framework.git
compile and test, build all jars, distribution zips and docs
./gradlew build
install all spring-* jars into your local Maven cache
./gradlew install
import sources into your IDE
Run ./import-into-eclipse.sh or read import-into-idea.md as appropriate.
本人电脑环境:mac OS X 10.8.2,jdk1.7.0_11,git 1.7.10.2
lie-mac:spring xionglie$ Java -version
java version "1.7.0_11"
Java(TM) SE Runtime Environment (build 1.7.0_11-b21)
Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode)
lie-mac:spring xionglie$ git --version
git version 1.7.10.2 (Apple Git-33)
操作过程:
lie-mac:~ xionglie$ cd ~/Downloads/spring/
lie-mac:spring xionglie$ git clone git://github.com/SpringSource/spring-framework.git
lie-mac:spring xionglie$ cd spring-framework
lie-mac:spring-framework xionglie$ ./import-into-eclipse.sh
注意:
(1).这里会执行5步操作,在第2步和第4步都要各导入(import)全部项目(~/Downloads/spring/spring-framework)到myeclipse中,相当于要导入两次,你只单独导入第4步的项目是不行的。
(2)STEP 1的时间会比较长,如果执行不下去,请多次执行 ./import-into-eclipse.sh ;
(3)myeclipse的编译环境要修改为jdk7,不要使用默认的jdk6。如我的jdk7的ire-home为 :/Library/Java/JavaVirtualMachines/jdk1.7.0_11.jdk/Contents/Home
-----------------------------------------------------------------------
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://springsource.org/downloads/sts
Otherwise, press enter and we'll begin. (按enter)
-----------------------------------------------------------------------
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. (按enter)
:buildSrc:compileJava UP-TO-DATE
:buildSrc:compileGroovy UP-TO-DATE
:buildSrc:processResources UP-TO-DATE
…省略….
BUILD SUCCESSFUL
Total time: 10 mins 30.351 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 /Users/xionglie/Downloads/spring/spring-framework
> 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: 16.551 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!
最终导入结果: