Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 683
rapt Avatar asked Dec 27 '22 08:12

rapt


1 Answers

Set my-project/src/main/java as the source folder (Project -> Properties -> Java Build Path -> Project -> Add Folder). Remove the old source folder.

Restart eclipse if necessary.

Simply put, Eclipse thinks that your project begins at my-project/src. Therefore, it expects all packages to descend from there, starting with main.java.

like image 162
Vladimir Shtokman Avatar answered Mar 16 '23 00:03

Vladimir Shtokman