I’ve learned a lot just reading Spring Framework source code, that’s why, I always recommend programmers to read it if they want to master Spring or review a real example of test cases, mock & stub objects, etc. So how can you have all the source code in Eclipse and compiling successfully? Let’s follow these simple steps:nnNote: I asume your using a Unix-like OS and you’ve installed Subversion & Apache Ant. No need for Subclipse or Subversive to have fun with unix commands :D
Create directory “springframework/svn-springframework” and download the source code using subversion.
mkdir -p springframework/svn-springframework svn co https://src.springframework.org/svn/spring-framework/trunk springframework/svn-springframework
Download dependencies and compile
Use Ant to do everything for you with the following commands:
cd springframework/svn-springframework/build-spring-frameworkn export ANT_OPTS='-Xmx1024m -XX:MaxPermSize=512m' ant
This task will take a little while so please be patient. After some minutes, if everything goes fine you’re going to see a message similar to:
BUILD SUCCESSFUL Total time: 20 minutes 20 seconds
If you don’t see it, it means that something went wrong so check the error messages and try to find a solution before executing Ant again. Spring should build successful to be sure that all the dependencies were downloaded correctly!
Note: At the time I’m writing this article, there is a problem in test case JdbcNamespaceIntegrationTest because a file doesn’t exist. The quickly solution is edit the test case:
And comment the method testMultipleDataSourcesHaveDifferentDatabaseNames and execute Ant again.
Import projects to Eclipse
Open Eclipse IDE and create a new workspace in the directory “springframework/workspace”. Go to preferences and select the classpath variables configuration:
When you use Ant in the previous step, it downloaded all the jar dependencies using Apache Ivy so you need to configure Eclipse to know where is the Ivy repository. Add a new variable called IVY_CACHE and find the directory springframework/svn-springframework/ivy-cache/repository.
Now everything is configured and you can import spring source code right clicking over the “Package Explorer View”
Select the option “Existing Projects into Workspace”
Click Browse and search for the directory springframework/svn-springframework
Finishing this step you’re going to have Spring Source code compiling in Eclipse so you can start looking at it and maybe if you want you can help with its development!
Note: At the time I’m writing this article the project org.springframework.integration-test won’t compile in Eclipse because some classes cannot be found. To solve this issue go to its configuration build path and add org.springframework.expression as require project.