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
For me the issue was that I was converting an existing project to maven, created the folder structures according to the documentation and it was showing the 'main' folder as part of the package. I followed the instructions similar to Jon Skeet / JWoodchuck and went into the Java build path, removed all broken build paths, and then added my build path to be 'src/main/java' and 'src/test/java', as well as the resources folders for each, and it resolved the issue.
I get this problem in Eclipse sometimes when importing an Android project that does not have a .classpath file. The one that Eclipse creates is not exactly the same one that Android expects. But, the Android .classpath files are usually all relative, so I just copy a correct .classpath file from another project over the incorrect .classpath. I've created a video that shows how I do this: https://www.youtube.com/watch?v=IVIhgeahS1Ynto
I just ran into this problem, and since Mr. Skeet's solution did not work for me, I'll share how I solved this problem.
It turns out that I opened the java file under the 'src' before declaring it a source directory.
After right clicking on the 'src' directory in eclipse, selecting 'build path', and then 'Use as Source Folder'
Close and reopen the already opened java file (F5 refreshing it did not work).
Provided the path to the java file from "prefix1" onwards lines up with the package in the file (example from the requester's question prefix1.prefix.packagename2). This should work
Eclipse should no longer complain about 'src.'
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.
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.
The only thing that worked for me is deleting the project and then importing it again. Works like a charm :)