Eclipse: How to add an existing source folder?

Eclipse

Eclipse Problem Overview


I have a directory called c:\RemoteSrc . Under this there are 3 directories which are currently source folders (I think? the icon is an open folder with a little orange grid in it) in my Eclipse project. I have dropped a new directory under c:\RemoteSrc which I also want to add to my project.

BUT

If I right click on my project and go "Build Path..." -> "Link Source" and try to add it it tells me "Folder already exists with a different case". Yes i KNOW that the folder already exists THATS WHY IM TRYING TO ADD IT.

Eclipse Solutions


Solution 1 - Eclipse

I think all you need to do is refresh the project. Eclipse does not automatically pick up folders (or files) dropped into it's project directory.

Solution 2 - Eclipse

A screen capture might help, but if the GUI is un-cooperative, you can:

  • close Eclipse
  • open the .classpath file which defines your project (it may be located in your workspace)
  • see if you can define a new classpathentry of kind "src": this is not the easy method, but that may give you an idea why the GUI refuses to define the same entry.

Solution 3 - Eclipse

For Linked Sources, you should have something like the following in your .classpath

<classpathentry kind="src" path="module_name"/>

With a corresponding matching entry (within <linkedResources>)in your .project

<link>
  <name>module_name</name>
  <type>2</type>
  <location>path/to/your/module</location>
</link>

NOTE: Removing a linked project doesn't necessarily remove it from the project.

Solution 4 - Eclipse

No need to close Eclipse. Open .project file using Notepad++, find link to the existing source/folder and delete it. Save the file. Refresh the project in Eclipse. Now you should be able to link it again.

Solution 5 - Eclipse

I had a problem where I had created a /src directory in my working directory and then wanted to link another directory with additional files to import. The "existing directory" turned out to be because the directory I was trying to link was also called "/src", even though the path was different. I guess Eclipse can't have two /src directories in the same project, similar to trying to mount two file systems at the same node. I rearranged the directories so there was only one /src, and all was well.

Solution 6 - Eclipse

There were conflicts when I tried to update my project which resulted in creation of multiple .classpath files.. SO removing the copies and reverting the latest .classpath file and then refreshing/rebuilding project ,solved the issue for me.

Hope it helps!

Solution 7 - Eclipse

Sometimes the simple refresh (Greg Adamski's answer) does not work, e.g. because the source folder is not in the src-directory (in my case, I had to reference Swagger auto-generated code which was located deep in the target/.... directory after a Maven Build).

In this case, right click the project, open the 'Build Path' -->'Configure Build Path' dialogue, select the 'Source' tab and select your additional source folder via the 'Add Folder' button.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionevilfredView Question on Stackoverflow
Solution 1 - EclipseGreg AdamskiView Answer on Stackoverflow
Solution 2 - EclipseVonCView Answer on Stackoverflow
Solution 3 - Eclipsenevets1219View Answer on Stackoverflow
Solution 4 - EclipseMichael ShlayenView Answer on Stackoverflow
Solution 5 - Eclipsesjr_eeView Answer on Stackoverflow
Solution 6 - EclipseDarshan KumarView Answer on Stackoverflow
Solution 7 - EclipseOceansunfishView Answer on Stackoverflow