This sounds like a trivial task, but I spent a good few hours reading various forums, blogs and other online material trying to find an answer to this, but I simply couldn’t! Now that I finally figured out how to do this, thought I’d write it up and hopefully someone will find this useful as well. Chances are that you are reading this post because you’ve also run into the same issue!
There are so many posts that describe how to create a new workspace when starting out a new project as well as how to ‘import’ existing source code into a new workspace. However, my scenario was that I had just checkedout several projects from svn (TortoiseSVN to be precise) into a root folder and wanted to use Eclipse to work directly on these files (which were already in sync with the repository). If I had created a new workspace and imported the source files, this would have created a duplicate folder structure in the new workspace, which I didn’t want to do. After checkingout the code, I had a folder structure similar to this:
The steps to create a new workspace and work directly on the source files are:
- Switch/create the new workspace location to be root folder – CLI in my case.
- Create a new Java Project – make sure the ‘Project name’ is the same as the folder name (this is the key!) – Eclipse automatically determines that this folder already exists and traverses the folder looking for relevant files. In the following example, I want to use Eclipse to work on the files under the ‘ModuleExtraction’ (not shown above) folder.
3. In the next screen you can see how Eclipse has included all the subfolders:
4. Repeat steps 2 and 3 for all the projects you want to include in your workspace. You should be able to see all your projects in Eclipse now. Here I have included two for my purposes:
Once you’ve done this process for at least one project, you’ll see the Eclipse .metadata folder in your root directory:
That’s it really!
By the way, if you come from a .net background, you can think of the workspace as your solution, and the .metadata folder as the place where all your preferences, global settings, projects etc. belonging to the solution are stored.
One more thing – there is subclipse that is suppose to integrate svn capabilities directly into eclipse. You need to install Subclipse SVN manager and do something like the following in eclipse:
a. Help -> Install new software
b. Under “Work with:”, put the URL: http://subclipse.tigris.org/update_1.8.x (or whatever the version you used) <enter>
c. Wait until “Subclipse” appears, then check the box next to it
d. Choose “Next”, then “Next”, accept license agreements, then “Finish”
e. “OK” for any warnings on unsigned content
f. Wait for install to complete
g. Restart Eclipse
Here is a pretty good guide that gives all the glory details related to setting subclipse up.
I have always used the Windows Explorer based technique (described here) when working with svn and I find it pretty easy and straightforward. Never used subclipse myself, but my colleagues who used to use subclipse have now started using the technique discussed here due to some issues they’ve run into when working with subclipse within eclipse. Better to try both and see for yourself which approach works best for you I guess.
Please post a comment if you found this useful 🙂