1. 程式人生 > >[自編號1-2]將spring framework源碼導入Spring Tool Suite中

[自編號1-2]將spring framework源碼導入Spring Tool Suite中

4.0 1.8 比較 簡單 成了 valid 問題 wildcard declare

先講基本步驟,如下:

  1. 去GitHub中下載spring framework的源碼,https://github.com/spring-projects/spring-framework/releases
  2. 下載3.2.X其中的一個版本;
  3. 安裝Gradle軟件,官網下載,解壓即可,設置GRADLE_HOME,和PATH。
  4. 命令行中運行gradle -v,檢查一下是否正確安裝配置;
  5. 命令行中運行spring framework根目錄下的import-into-eclipse.bat
  6. 連續兩次回車,就可以開始自動構建;
  7. 中間出現停止不前的情況裏,按ctrl+c終止,再運行就可以進行下去;
  8. 過程需要花些時間(幾個小時都有可能),視下載各種依賴jar包和dom文件的速度而定;
  9. 在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 the java Virtual machine"的錯誤。

查看build.gradle和gradlew.bat中,可以找出原因:

build.gradle中:

Java代碼 技術分享圖片
  1. compileJava {
  2. sourceCompatibility=1.6
  3. targetCompatibility=1.6
  4. }
  5. compileTestJava {
  6. sourceCompatibility=1.8
  7. targetCompatibility=1.8
  8. }

可以看出這個版本的test代碼要求用1.8。

gradlew.bat中

Java代碼 技術分享圖片
  1. 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內存溢出情況

錯誤信息如下:

Java代碼 技術分享圖片
  1. FAILURE: Build failed with an exception.
  2. * What went wrong:
  3. Execution failed for task ‘:referencePdf‘.
  4. > GC overhead limit exceeded
  5. * Try:
  6. Run with --info or --debug option to get more log output.
  7. * Exception is:
  8. org.gradle.api.tasks.TaskExecutionException: Execution failed for task ‘:referen
  9. cePdf‘.
  10. at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.ex
  11. ecuteActions(ExecuteActionsTaskExecuter.java:68)
  12. at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.ex
  13. ecute(ExecuteActionsTaskExecuter.java:46)
  14. at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExec
  15. uter.execute(PostExecutionAnalysisTaskExecuter.java:34)
  16. at org.gradle.api.internal.changedetection.CacheLockHandlingTaskExecuter
  17. $1.run(CacheLockHandlingTaskExecuter.java:34)
  18. at org.gradle.internal.Factories$1.create(Factories.java:22)
  19. at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(Def
  20. aultCacheAccess.java:179)
  21. at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(Def
  22. aultCacheAccess.java:232)
  23. at org.gradle.cache.internal.DefaultPersistentDirectoryStore.longRunning
  24. Operation(DefaultPersistentDirectoryStore.java:138)
  25. at org.gradle.api.internal.changedetection.DefaultTaskArtifactStateCache
  26. Access.longRunningOperation(DefaultTaskArtifactStateCacheAccess.java:83)
  27. at org.gradle.api.internal.changedetection.CacheLockHandlingTaskExecuter
  28. .execute(CacheLockHandlingTaskExecuter.java:32)
  29. at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.exec
  30. ute(SkipUpToDateTaskExecuter.java:55)
  31. at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execut
  32. e(ValidatingTaskExecuter.java:57)
  33. at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecu
  34. ter.execute(SkipEmptySourceFilesTaskExecuter.java:41)
  35. at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter
  36. .execute(SkipTaskWithNoActionsExecuter.java:51)
  37. at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execut
  38. e(SkipOnlyIfTaskExecuter.java:52)
  39. at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter
  40. .execute(ExecuteAtMostOnceTaskExecuter.java:42)
  41. at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailur
  42. e(AbstractTask.java:247)
  43. at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.executeTask(De
  44. faultTaskPlanExecutor.java:52)
  45. at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.processTask(De
  46. faultTaskPlanExecutor.java:38)
  47. at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(Defaul
  48. tTaskPlanExecutor.java:30)
  49. at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(Defau
  50. ltTaskGraphExecuter.java:83)
  51. at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTask
  52. ExecutionAction.java:29)
  53. at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecute
  54. r.java:61)
  55. at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExec
  56. uter.java:23)
  57. at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecu
  58. ter.java:67)
  59. at org.gradle.api.internal.changedetection.TaskCacheLockHandlingBuildExe
  60. cuter$1.run(TaskCacheLockHandlingBuildExecuter.java:31)
  61. at org.gradle.internal.Factories$1.create(Factories.java:22)
  62. at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAcc
  63. ess.java:124)
  64. at org.gradle.cache.internal.DefaultCacheAccess.useCache(DefaultCacheAcc
  65. ess.java:112)
  66. at org.gradle.cache.internal.DefaultPersistentDirectoryStore.useCache(De
  67. faultPersistentDirectoryStore.java:130)
  68. at org.gradle.api.internal.changedetection.DefaultTaskArtifactStateCache
  69. Access.useCache(DefaultTaskArtifactStateCacheAccess.java:79)
  70. at org.gradle.api.internal.changedetection.TaskCacheLockHandlingBuildExe
  71. cuter.execute(TaskCacheLockHandlingBuildExecuter.java:29)
  72. at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecute
  73. r.java:61)
  74. at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExec
  75. uter.java:23)
  76. at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecu
  77. ter.java:67)
  78. at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildEx
  79. ecutionAction.java:32)
  80. at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecute
  81. r.java:61)
  82. at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecute
  83. r.java:54)
  84. at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(Default
  85. GradleLauncher.java:158)
  86. at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradle
  87. Launcher.java:113)
  88. at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLaun
  89. cher.java:81)
  90. at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.jav
  91. a:38)
  92. at org.gradle.launcher.exec.InProcessGradleLauncherActionExecuter.execut
  93. e(InProcessGradleLauncherActionExecuter.java:39)
  94. at org.gradle.launcher.exec.InProcessGradleLauncherActionExecuter.execut
  95. e(InProcessGradleLauncherActionExecuter.java:25)
  96. at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:50)
  97. at org.gradle.api.internal.Actions$RunnableActionAdapter.execute(Actions
  98. .java:137)
  99. at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.
  100. execute(CommandLineActionFactory.java:201)
  101. at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.
  102. execute(CommandLineActionFactory.java:174)
  103. at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(
  104. CommandLineActionFactory.java:170)
  105. at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(
  106. CommandLineActionFactory.java:139)
  107. at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionRep
  108. ortingAction.java:33)
  109. at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionRep
  110. ortingAction.java:22)
  111. at org.gradle.launcher.Main.doAction(Main.java:48)
  112. at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
  113. at org.gradle.launcher.Main.main(Main.java:39)
  114. at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBoots
  115. trap.java:50)
  116. at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.j
  117. ava:32)
  118. at org.gradle.launcher.GradleMain.main(GradleMain.java:26)
  119. at org.gradle.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.ja
  120. va:33)
  121. at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:130)
  122. at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:48)
  123. Caused by: java.lang.OutOfMemoryError: GC overhead limit exceeded
  124. at org.apache.fop.area.inline.TextArea.addWord(TextArea.java:68)
  125. at org.apache.fop.layoutmgr.inline.TextLayoutManager.createTextArea(Text
  126. LayoutManager.java:483)
  127. at org.apache.fop.layoutmgr.inline.TextLayoutManager.addAreas(TextLayout
  128. Manager.java:361)
  129. at org.apache.fop.layoutmgr.inline.LineLayoutManager.addInlineArea(LineL
  130. ayoutManager.java:1716)
  131. at org.apache.fop.layoutmgr.inline.LineLayoutManager.addAreas(LineLayout
  132. Manager.java:1568)
  133. at org.apache.fop.layoutmgr.BlockLayoutManager.addAreas(BlockLayoutManag
  134. er.java:395)
  135. at org.apache.fop.layoutmgr.BlockLayoutManager.addAreas(BlockLayoutManag
  136. er.java:395)
  137. at org.apache.fop.layoutmgr.BlockLayoutManager.addAreas(BlockLayoutManag
  138. er.java:395)
  139. at org.apache.fop.layoutmgr.BlockLayoutManager.addAreas(BlockLayoutManag
  140. er.java:395)
  141. at org.apache.fop.layoutmgr.AreaAdditionUtil.addAreas(AreaAdditionUtil.j
  142. ava:121)
  143. at org.apache.fop.layoutmgr.FlowLayoutManager.addAreas(FlowLayoutManager
  144. .java:305)
  145. at org.apache.fop.layoutmgr.PageBreaker.addAreas(PageBreaker.java:241)
  146. at org.apache.fop.layoutmgr.AbstractBreaker.addAreas(AbstractBreaker.jav
  147. a:508)
  148. at org.apache.fop.layoutmgr.AbstractBreaker.addAreas(AbstractBreaker.jav
  149. a:371)
  150. at org.apache.fop.layoutmgr.PageBreaker.doPhase3(PageBreaker.java:262)
  151. at org.apache.fop.layoutmgr.AbstractBreaker.doLayout(AbstractBreaker.jav
  152. a:346)
  153. at org.apache.fop.layoutmgr.AbstractBreaker.doLayout(AbstractBreaker.jav
  154. a:264)
  155. at org.apache.fop.layoutmgr.PageSequenceLayoutManager.activateLayout(Pag
  156. eSequenceLayoutManager.java:106)
  157. at org.apache.fop.area.AreaTreeHandler.endPageSequence(AreaTreeHandler.j
  158. ava:234)
  159. at org.apache.fop.fo.pagination.PageSequence.endOfNode(PageSequence.java
  160. :123)
  161. at org.apache.fop.fo.FOTreeBuilder$MainFOHandler.endElement(FOTreeBuilde
  162. r.java:340)
  163. at org.apache.fop.fo.FOTreeBuilder.endElement(FOTreeBuilder.java:169)
  164. at org.apache.xalan.transformer.TransformerIdentityImpl.endElement(Trans
  165. formerIdentityImpl.java:1050)
  166. at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source
  167. )
  168. at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknow
  169. n Source)
  170. at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContent
  171. Dispatcher.dispatch(Unknown Source)
  172. at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Un
  173. known Source)
  174. at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
  175. at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
  176. at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
  177. at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
  178. at org.apache.xalan.transformer.TransformerIdentityImpl.transform(Transf
  179. ormerIdentityImpl.java:432)
  180. 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時,可能會遇到一個問題,錯誤日誌如下:

Java代碼 技術分享圖片
  1. FAILURE: Build failed with an exception.
  2. * What went wrong:
  3. Execution failed for task ‘:spring-webmvc-tiles3:eclipseClasspath‘.
  4. > Could not resolve all dependencies for configuration ‘detachedConfiguration2‘.
  5. > Module version group:org.springframework, module:spring-webmvc-tiles3, vers
  6. ion:3.2.1.RELEASE, configuration:detachedConfiguration2 declares a dependency on
  7. configuration ‘runtimeMerge‘ which is not declared in the module descriptor for
  8. group:org.springframework, module:spring-web, version:3.2.1.RELEASE
  9. * Try:
  10. Run with --stacktrace option to get the stack trace. Run with --info or --debug
  11. option to get more log output.

從日誌中可以看出是在build spring-webmvc-tiles3項目時,生成eclipse的.classpath文件時出錯,打開其它正常導入的項目的.classpath看下這個文件包含了哪些信息,如打開spring-aop項目的:

Java代碼 技術分享圖片
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <classpath>
  3. <classpathentry kind="output" path="spring-aop/bin/eclipse"/>
  4. <classpathentry output="bin/main" kind="src" path="src/main/java"/>
  5. <classpathentry output="bin/main" kind="src" path="src/main/resources"/>
  6. <classpathentry output="bin/test" kind="src" path="src/test/java"/>
  7. <classpathentry output="bin/test" kind="src" path="src/test/resources"/>
  8. <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER" exported="true"/>
  9. <classpathentry kind="src" path="/spring-core" exported="true"/>
  10. <classpathentry kind="src" path="/spring-beans" exported="true"/>
  11. <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"/>
  12. <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/com.jamonapi/jamon/2.4/jar/e2ad6f45c2ba72d8fa798b68a5f9b73c9f047756/jamon-2.4.jar"/>
  13. <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"/>
  14. <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"/>
  15. <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"/>
  16. <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"/>
  17. <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"/>
  18. <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"/>
  19. <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"/>
  20. <classpathentry kind="lib" path="D:/DevelopTools/spring-framework-3.2.1.RELEASE/spring-core/build/libs/spring-cglib-repack-3.0.jar" exported="true"/>
  21. </classpath>

而spring-webmvc-tiles3下根本就沒有.classpath的影子,沒得比較,雖然上面的錯誤日誌的E文都認識,但還是看不出它在講什麽,不過大體能看得出是依賴出了問題,那只能是想辦法順藤摸瓜了。重新打開build.gradle,找到有關spring-webmvc-tiles3項目的描述,如下:

Java代碼 技術分享圖片
  1. project("spring-webmvc-tiles3") {
  2. description = "Spring Framework Tiles3 Integration"
  3. merge.into = project(":spring-webmvc")
  4. dependencies {
  5. provided(project(":spring-context"))
  6. provided(project(":spring-web"))
  7. provided("javax.el:el-api:1.0")
  8. provided("javax.servlet:jstl:1.2")
  9. provided("javax.servlet.jsp:jsp-api:2.1")
  10. optional("org.apache.tiles:tiles-request-api:1.0.1")
  11. optional("org.apache.tiles:tiles-api:3.0.1")
  12. optional("org.apache.tiles:tiles-core:3.0.1") {
  13. exclude group: "org.slf4j", module: "jcl-over-slf4j"
  14. }
  15. optional("org.apache.tiles:tiles-servlet:3.0.1") {
  16. exclude group: "org.slf4j", module: "jcl-over-slf4j"
  17. }
  18. optional("org.apache.tiles:tiles-jsp:3.0.1") {
  19. exclude group: "org.slf4j", module: "jcl-over-slf4j"
  20. }
  21. optional("org.apache.tiles:tiles-extras:3.0.1") {
  22. exclude group: "org.slf4j", module: "jcl-over-slf4j"
  23. }
  24. optional("org.apache.tiles:tiles-el:3.0.1") {
  25. exclude group: "org.slf4j", module: "jcl-over-slf4j"
  26. }
  27. provided("javax.servlet:javax.servlet-api:3.0.1")
  28. testCompile("org.slf4j:slf4j-jcl:${slf4jVersion}")
  29. }
  30. }

打開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中加上如下部分:

Java代碼 技術分享圖片
  1. eclipseClasspath {
  2. downloadSources = false; // required for eclipseClasspath to work
  3. }

關於spring-webmvc-tiles3項目的腳本、就變成這樣了:

Java代碼 技術分享圖片
  1. project("spring-webmvc-tiles3") {
  2. description = "Spring Framework Tiles3 Integration"
  3. merge.into = project(":spring-webmvc")
  4. dependencies {
  5. provided(project(":spring-context"))
  6. provided(project(":spring-web"))
  7. provided("javax.el:el-api:1.0")
  8. provided("javax.servlet:jstl:1.2")
  9. provided("javax.servlet.jsp:jsp-api:2.1")
  10. optional("org.apache.tiles:tiles-request-api:1.0.1")
  11. optional("org.apache.tiles:tiles-api:3.0.1")
  12. optional("org.apache.tiles:tiles-core:3.0.1") {
  13. exclude group: "org.slf4j", module: "jcl-over-slf4j"
  14. }
  15. optional("org.apache.tiles:tiles-servlet:3.0.1") {
  16. exclude group: "org.slf4j", module: "jcl-over-slf4j"
  17. }
  18. optional("org.apache.tiles:tiles-jsp:3.0.1") {
  19. exclude group: "org.slf4j", module: "jcl-over-slf4j"
  20. }
  21. optional("org.apache.tiles:tiles-extras:3.0.1") {
  22. exclude group: "org.slf4j", module: "jcl-over-slf4j"
  23. }
  24. optional("org.apache.tiles:tiles-el:3.0.1") {
  25. exclude group: "org.slf4j", module: "jcl-over-slf4j"
  26. }
  27. provided("javax.servlet:javax.servlet-api:3.0.1")
  28. testCompile("org.slf4j:slf4j-jcl:${slf4jVersion}")
  29. }
  30. eclipseClasspath {
  31. downloadSources = false; // required for eclipseClasspath to work
  32. }
  33. }

重新運行命令,這一次終於讓我看到了BUILD SUCCESSFUL的字樣了……

成功build完成後,可以看到spring目錄下的spring-webmvc-tiles3項目也正常生成了導入eclipse需要的文件。打開.classpath查看一下:

Java代碼 技術分享圖片
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <classpath>
  3. <classpathentry kind="output" path="spring-webmvc-tiles3/bin/eclipse"/>
  4. <classpathentry output="bin/main" kind="src" path="src/main/java"/>
  5. <classpathentry output="bin/test" kind="src" path="src/test/java"/>
  6. <classpathentry output="bin/test" kind="src" path="src/test/resources"/>
  7. <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER" exported="true"/>
  8. <classpathentry kind="src" path="/spring-context" exported="true"/>
  9. <classpathentry kind="src" path="/spring-web" exported="true"/>
  10. <classpathentry kind="src" path="/spring-webmvc" exported="true"/>
  11. <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"/>
  12. <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"/>
  13. <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"/>
  14. <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"/>
  15. <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"/>
  16. <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"/>
  17. <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"/>
  18. <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"/>
  19. <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/javax.servlet/jstl/1.2/jar/74aca283cd4f4b4f3e425f5820cda58f44409547/jstl-1.2.jar"/>
  20. <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"/>
  21. <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"/>
  22. <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/junit/junit/4.11/jar/4e031bb61df09069aeb2bffb4019e7a5034a4ee0/junit-4.11.jar"/>
  23. <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"/>
  24. <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"/>
  25. <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"/>
  26. <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"/>
  27. <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"/>
  28. <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"/>
  29. <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"/>
  30. <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"/>
  31. <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"/>
  32. <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"/>
  33. <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"/>
  34. <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"/>
  35. <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/aopalliance/aopalliance/1.0/jar/235ba8b489512805ac13a8f9ea77a1ca5ebe3e8/aopalliance-1.0.jar"/>
  36. <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"/>
  37. <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"/>
  38. <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"/>
  39. <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/com.google.guava/guava/r09/jar/9c8991d491d714053d300de0f8657d95780ff923/guava-r09.jar"/>
  40. <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"/>
  41. <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"/>
  42. <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"/>
  43. <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"/>
  44. <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"/>
  45. <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"/>
  46. <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/oro/oro/2.0.8/jar/5592374f834645c4ae250f4c9fbb314c9369d698/oro-2.0.8.jar"/>
  47. <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"/>
  48. <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"/>
  49. <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"/>
  50. <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"/>
  51. <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"/>
  52. <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"/>
  53. <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"/>
  54. <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"/>
  55. <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/jboss/javassist/3.7.ga/jar/6d271a67a1d8718bfb225ace5a25f1c09427c9f8/javassist-3.7.ga.jar"/>
  56. <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/ognl/ognl/2.7.3/jar/8c391fdc943b352045bd35c4f57306ccc6442f7c/ognl-2.7.3.jar"/>
  57. <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"/>
  58. <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"/>
  59. <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"/>
  60. <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/org.objenesis/objenesis/1.2/jar/bfcb0539a071a4c5a30690388903ac48c0667f2a/objenesis-1.2.jar"/>
  61. <classpathentry kind="lib" path="C:/Users/so/.gradle/caches/artifacts-15/filestore/cglib/cglib-nodep/2.2/jar/59afed7ab65e7ec6585d5bc60556c3cbd203532b/cglib-nodep-2.2.jar"/>
  62. <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"/>
  63. <classpathentry kind="src" path="/spring-aop" exported="true"/>
  64. <classpathentry kind="src" path="/spring-core" exported="true"/>
  65. <classpathentry kind="src" path="/spring-beans" exported="true"/>
  66. <classpathentry kind="src" path="/spring-expression" exported="true"/>
  67. <classpathentry kind="src" path="/spring-instrument" exported="true"/>
  68. <classpathentry kind="src" path="/spring-oxm" exported="true"/>
  69. <classpathentry kind="src" path="/spring-context-support" exported="true"/>
  70. <classpathentry kind="src" path="/spring-jdbc" exported="true"/>
  71. <classpathentry kind="src" path="/spring-tx" exported="true"/>
  72. </classpath>

果然沒有sourcepath的信息。

折騰了那麽久,終於到了可以看一下成果的時候了。

Spring Tool Suite說簡單一點就是Spring家的eclipse,去官網下一個最新版,安裝上。

打開STS,菜單File->import選擇General下面的Exsiting projects into workspace,勾選要導入的子項目,確定即可。


技術分享圖片

成果如上,齊齊整整,沒有錯誤,挺好!

[自編號1-2]將spring framework源碼導入Spring Tool Suite中