Import spring-framework into Eclipse

Basically, you just need to follow this guide from spring-framwork github page

Note that I checkout the master branch

From the offical guide, there are 6 steps.

  1. Precompile spring-oxm with ./gradlew :spring-oxm:compileTestJava
  2. Import into Eclipse (File -> Import -> Gradle -> Existing Gradle Project -> Navigate to directory -> Select Finish)
  3. If prompted, exclude the spring-aspects module (or after the import by closing or deleting the project)
  4. In the spring-oxm project, add the two folders (castor and jaxb) in build/generated-sources to the build path (right click on them and select Build Path -> Use as Source Folder)
  5. To apply project specific settings run ./gradlew eclipseBuildship
  6. Code away

Here I record problems encountered which may be helpful to someone else.

  1. Precompile spring-oxm with ./gradlew :spring-oxm:compileTestJava

I have network problem in downloading gradle distribution online, it’s extremely slow.

To workaround it, I first used the greate tool aria2c to download gradle zip file to my local.

1
aria2c -x 8 -s 8 -k 1M  https://services.gradle.org/distributions/gradle-4.10.3-bin.zip

It issues 8 threads to download the target file parallelly.

Then, locate the gradle-wrapper.properties file under spring-framework/gradle/wrapper, modify its distributionUrl property

1
2
#distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-bin.zip
distributionUrl=file:///home/benson/Downloads/gradle-4.10.3-bin.zip

In this way, gradlew will download the zip file from your local.

  1. In the spring-oxm project, add the two folders (castor and jaxb) in build/generated-sources to the build path (right click on them and select Build Path -> Use as Source Folder)

Successfully go through step 2 to 3. But then I couldn’t find build folder under spring-oxm, in Eclipse package exploreer.

To show it, you need to ensure

  • The Java Element Filter in package explorer have Gradle build folder unchecked.

  • Resource > Resource Filters in project property doesn’t have rule to exclude build folder.

Besides this, I also encountered error that

xxx is not accessible due to restriction on required library C:\Program Files\Java\jdk1.8.0_181\jre\lib\rt.jar

I found one solution for this from Stackoverlow here

I quote the solution here

  1. Go to the Build Path settings in the project properties.
  2. Remove the JRE System Library
  3. Add it back; Select “Add Library” and select the JRE System Library. The default worked for me.

Lastly, there is another error under project spring-beans. It says that

GroovyDynamicElementReader cannot be resolved to a type

It requires to download corresponding Groovy plugin to resolve this problem.