Importing existing source code into Eclipse

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:

  1. Switch/create the new workspace location to be root folder – CLI in my case.
  2. 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: (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 🙂

This entry was posted in General and tagged , , , . Bookmark the permalink.

33 Responses to Importing existing source code into Eclipse

  1. dvrraoao says:

    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

  2. Dimitra Micha says:

    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..:-)

  3. Anonymous says:

    Excellent and very useful

  4. Anonymous says:

    big thanks to this really saved me the hassle and effort that i could have wasted if i was not able to read this.. THANKS!

  5. Pingback: Delicious Bookmarks for May 22nd through May 23rd « Lâmôlabs

  6. Saved my day..! Thanks..

  7. Rasul says:

    This was really useful information.. I wasted 2 days before reading this article.

  8. Dhaval says:

    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.

  9. saurabh says:

    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.

  10. tej says:

    Thanks a lot, it solved my problem.

  11. Ravi says:

    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.

  12. badi8beach says:

    very helpful, thank you

  13. John Gilmore says:

    Really great write-up, but this solution seems to only work for Java files. Not C/C++ or Google Go, for example.

  14. norore says:

    Thank you very much for this post! It was really usefull for me and I will recommend it to my surroundings! 🙂

  15. Ram says:

    Hi All,
    I’ve created a project structure in my local workspace where my Eclipse workspace is pointing to. just tried to import the project which was created manually. Though it has the same kind of folder structure as like the project which was builded in eclipse. Eclipse is not letting me to import the project.

    Please help in this.


    • Is this a regular Java project that you are not trying to import into eclipse? Make sure the naming is exactly as mentioned in this post (2nd point). Not sure what I can suggest other than say try to follow the steps carefully and make sure eclipse ‘Project name’ is the same as the folder name.

  16. Anonymous says:

    Thank you very much! Very usefull

  17. Pingback: Choosing the Best Python IDE | Pedro KrogerPedro Kroger

    • I don’t do much Java development anymore (moved to C#, so Visual Studio is pretty much the only option). I had tried a few IDEs myself, and between NetBeans and Eclipse I actually preferred the UI of eclipse better. Didn’t spend much time with the other editors. There are plenty of threads debating which one’s the best IDE, so I guess it comes down to the requirements and individual preferences. Feel free to suggest what you feel is better/best.

  18. vgaxiola says:

    Just what I was looking for, excellent tutorial, thanks.

  19. leboski says:

    This is great

  20. Anonymous says:

    Good point in comparing the Eclipse workspace to a .NET solution file. It took me quite a while to realize that that’s basically how it was set up. Is the intent for each overarching ‘project’ (i.e. ‘solution’) to have its own workspace, or is it fine to have all of them share one workspace? (Note: I’m using PyDev in ordinary Eclipse.)

    • Well, a project and solution are different, right? A solution typically would contain multiple (related) projects. Similarly, a workspace in eclipse would typically contain multiple (related) projects. I don’t think it makes a lot of sense for each project to have its own workspace.

  21. Anonymous says:

    Really thank you thank you and thank you!!!

  22. zakaria says:

    Thanks it was helpful

  23. chezpaulPaul says:

    Thanks for the advice.
    I got my github java repo opened in the Eclipse workplace but now, a stupid question. How do I compile this and where does the java app or applet go to?
    I hit RUN and it went through it’s paces but I don’t know where it went to.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s