I have a problem importing an external project. I go File -> Import... -> Existing Projects into Workspace, choose the folder where the project is located and everything is imported - but the package names of the project don't seem to be what Eclipse expects. The package names all have a prefix:
prefix.packagename1
prefix.packagename2
etc.
But Eclipse expects
src.prefix1.prefix.packagename1
src.prefix1.prefix.packagename2
etc. because the directory is src/prefix1/prefix/package1
I don't really want to mess around with external code. How do I tell Eclipse to ignore the directory "src/prefix1"? Or what else can I do?
Happens for me after failed builds run outside of the IDE. If cleaning your workspace doesn't work, try: 1) Delete all projects 2) Close and restart STS/eclipse, 3) Re-import the projects
I happened to have the same problem just now. However, the first few answers don't work for me.I propose a solution:change the .classpath file.For example,you can define the classpathentry node's path like this: path="src/prefix1/java" or path="src/prefix1/resources". Hope it can help.
Suppose your project has a package like
package name1.name2.name3.name4
(declared package)Your package explorer shows
package top level named name1.name2
sub packages named name3.name4
You will have errors because Eclipse extracts the package name from the file directory structure on disk starting at the point you import from.
My case was a bit more involved, perhaps because I was using a symbolic link to a folder outside my workspace.
I first tried Build Path.Java Build Path.Source Tab.Link Source Button.Browse to the folder before name1 in your package.Folder-name as you like (i think). But had issues.
Then I removed the folder from the build path and tried File > Import... > General > File System > click Next > From Directory > Browse... to folder above name1 > click Advanced button > check Create links in workspace > click Finish button.
Click Build path --> Remove from build path.
Now go the folder prefix1 in the folder section of your project.
Right click on it --> Build path --> Use as source folder.
Done. The package folder wont show any error now. If it still shows, just restart the project.
Move your problem *.java files to other folder.
Click 'src' item and press "F5".
Red crosses will dissaperar.
Return your *.java files to "package path", click 'src' item and press "F5".
All should be ok.
Go to src folder of the project and copy all the code from it to some temporary location and build the project. And now copy the actual code from temporary location to project src. And run the build again. Problem will be resolved.
Note: This is specific to eclipse.