Search code examples
eclipsemavenbuildpath

Eclipse: "declared package does not match the expected package", but buildpath does define the declared package


In a maven project called my-project, eclipse keeps telling me

The declared package "com.myself" does not match the expected package "main.java.com.myself"

although I verified that in the project's build path, I have an entry:

my-project/src/main/java
    Included: **/*.java
    Excluded: (None)
    Native library location: (None)
    Ignore optional compile problems: No

What could be the problem then?

What is the easiest way to fix the problem?

I suspect that something is wrong with the eclipse settings files, because after importing the project to the workspace and converting it to a maven project, I had to change the folder structure manually in to get the conventional folder structure of a maven web project. But it could be that during those changes, something was not understood properly by eclipse.

Also, maven is able to build my project (from within eclipse, as well as from the command line).

I'm just getting those compilation error from eclipse.

P.S. I've already tried project > clean, but it did not help.


Solution

    1. I copied the project folder to some place outside of my eclipse workspace.
    2. Then I deleted the project from the eclipse project explorer and the workspace.
    3. Now I created a new java project with the same name, and imported the original project that I saved at (1).
    4. Tah dah! no compilation errors.