2

Apologies if this has been asked before - if it has, I'm obviously searching for the wrong thing. It's not the first time I've been stumped by java, eclipse and how they find source files.

I have a folder of java sources and I wish to copy them in to the 'src/com' folder and have this 'just work'. If I copy the files directly, eclipse and java fail to recognise them so I assume that somewhere there's a file that tells the IDE that there's a folder of files in there that's included in the project. I'd like to know how to do this via config files and via the IDE UI.

Unfortunately, the two obvious files (.project and .classpath) don't seem to reference the existing directories at all (.classpath contains a line

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

that I'd assume would auto-scan that directory for files but it doesn't appear to)

Finally, are .classpath and .project java concepts or eclipse concepts?

Thank you for your time.

Luther
  • 1,786
  • 3
  • 21
  • 38
  • .classpath and .project are Eclipse-specific files. – Jakub Zaverka Jan 27 '14 at 13:03
  • 1
    They are eclipse concepts. Have you right-clicked on the project in the explorer view and chosen "Refresh"? That should be sufficient. – JB Nizet Jan 27 '14 at 13:03
  • Doh, I pressed F5 and even restarted the IDE and that didn't do the job so I simply assumed they needed to be referenced explicitly. It seems odd that restarting it did nothing - does Eclipse cache a lot of things but not watch folders diligently? – Luther Jan 27 '14 at 13:05
  • Does the package hierarchy strictly match with the folder hierarchy under src? – JB Nizet Jan 27 '14 at 13:10

2 Answers2

5

Eclipse has its own list of files in the folders stored in the .metadata, you have to use File > Refresh to tell it to refresh that list.

You can also tell it to do the refresh automatically in Preferences > General > Workspace Refresh using native hooks or polling check box.

You can also do this programatically using the refreshLocal method of IResource (so also in IProject, IFolder and IFile).

greg-449
  • 109,219
  • 232
  • 102
  • 145
1

If I copy the files directly, eclipse and java fail to recognise them

Eclipse does not watch the file system, so if you make any changes to project files outside the IDE, you should refresh the project. Same story with tools that execute as external processes, e.g. ant builds.

so I assume that somewhere there's a file that tells the IDE that there's a folder of files in there that's included in the project

You may configure sources, output directories and dependencies in "Build path" section of project config. Or RMB on project and select "Configure build path".

Finally, are .classpath and .project java concepts or eclipse concepts?

Yes, but they are also recognized in other IDEs, for instance IDEA Intellij. See What's in an Eclipse .classpath/.project file?

Community
  • 1
  • 1