Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import an existing directory into Eclipse?

Tags:

eclipse

I am on a mac, but I don't think it will make a difference. I have a directory that I want to fully import/add into Eclipse. What I did is this:

  1. Right click import
  2. General → Existing Projects into Workspace

Then when I click browse for either root directory or archive file and select the folder I can't click finish. The folder is empty and just contains a few folders but for some reason I can't click finish.

like image 732
Exploit Avatar asked Dec 23 '11 00:12

Exploit


People also ask

How do I import a folder?

Set up an import folderGo to Preferences > Import folders. Click Connect a folder to open a file picker window. Locate the folder you want to connect, and click Select.

How do I add an existing class in Eclipse?

You need to import the class into the referencing class. Ctrl + Space (while highlighting the classname) should do the trick in Eclipse.


2 Answers

The Eclipse UI is a little bit confusing.

The Import -> "Existing projects into workspace" actually means import "Existing Eclipse projects into workspace". That's why you can't click on finish: the import option looks for a .project file (the file used by Eclipse to store the project options) in the directory that you have chosen.

To import existing source code that doesn't have an Eclipse project file you have the following options (I suppose that you want to create a Java project):

  1. New project inside the workspace dir: Create a new empty Java project into the workspace (File->New->Java Project). Then right click on the source folder and choose Import...->General->File system then choose your files, and it will make a copy of your files.

    Tip: you can drag&drop your files from the Finder into the src folder.

  2. Create an eclipse project in your existing dir: Create a new Java project, but in the "New Java Project" window:

    • Un check the Use default location option, and choose the directory where is your non-Eclipse project.
    • Click Next and configure the sub-directories of your non-Eclipse project where the source files are located. And you are done :)
like image 154
Diego Avatar answered Sep 23 '22 17:09

Diego


There is no need to create a Java project and let unnecessary Java dependencies and libraries to cling into the project. The question is regarding importing an existing directory into eclipse

Suppose the directory is present in C:/harley/mydir. What you have to do is the following:

  • Create a new project (Right click on Project explorer, select New -> Project; from the wizard list, select General -> Project and click next.)

  • Give to the project the same name of your target directory (in this case mydir)

  • Uncheck Use default location and give the exact location, for example C:/harley/mydir

  • Click on Finish

You are done. I do it this way.

like image 24
spiderman Avatar answered Sep 22 '22 17:09

spiderman