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
An excellent tutorial perfectly worked for importing java source files
but I am still struggling with same problem for importing android source file using eclipse
the above did not work for android source files
Thanks for the feedback/comment
Glad it helped you in some way, but I’ve never worked with Android source files so unfortunately not able to even make a suggestion. I wonder what’s so different about them from java files though..
Hey!! This is very useful. I would like to create a java application using an existing source code, but I don’t know what is better: to import the source code first or to create first my project and then import it?
Sorry..but I’m a bit unclear as to what exactly you want to do. When you say ‘existing code’, you mean checked out from svn right? In which case can’t you import the source into eclipse (as mentioned in this post) and then work on it locally? Of course you have the option to check-in your code once you are done..:-)
Excellent and very useful
big thanks to this blog..it really saved me the hassle and effort that i could have wasted if i was not able to read this.. THANKS!
Pingback: Delicious Bookmarks for May 22nd through May 23rd « Lâmôlabs
Saved my day..! Thanks..
Gosh.. Is this your blog Thusitha ayya? Keep this up…
Samitha (Auckland)
Yes, it is..thanks!
Quite a nice blog you got there yourself Samitha – http://mycola.info/! Hope your PhD work is going well
This was really useful information.. I wasted 2 days before reading this article.
I have a similar setup. But every time I commit I have to go to the directory and then commit. Now that I have installed subclipse, I am not sure how to link my existing project to svn.
Well, actually, that’s exactly what I do. I have eclipse pointing at the local svn checkout (per this post), but use SVN integration in Windows Explorer to do all the commits/updates. I don’t have subeclipse installed at all since I (personal preference) find it a lot easier just to use Windows Explorer to do my svn commits/updates.
Thanks a lot. I was facing the same issue again and again and was just doing some workaround of creating a new project and then importing these files there. Your post has really helped.
Thanks a lot, it solved my problem.
Really nice explanation. This is a tricky way of importing svn projects into Eclipse unlike normal importing of projects. If is not this way of import, project will not be active in Eclipse workspace. Thanks a lot. It solved my problem.
very helpful, thank you
Really great write-up, but this solution seems to only work for Java files. Not C/C++ or Google Go, for example.