Eclipse says package declaration does not match expected package ""

I use Maven to create my project. When I look at it in Eclipse, it complains that

Package declaration does not match expected package ""

Maven can successfully create a project.

Eclipse project view

+4
source share
1 answer

Eclipse must recognize a specific folder as a "source folder" in order to correctly interpret the contents as Java source files.

Usually, if you create a Java project, Eclipse creates a single folder called 'src' and marks it as a “Source Folder”. However, if you are dealing with installing the Maven project by default, Eclipse will not automatically recognize "src / main / java" as the source folder (unless of course you use the plugin).

If you are not sure if Eclipse sees your folder as a “source folder” or just a regular folder, look at the icons (note the small package symbol in the lower left corner):

enter image description here

Since you, as you said, work with Maven, you must either use the Maven plugin for Eclipse or Maven generate the necessary meta files for Eclipse. This can be done using the command (generates .classpath and .project files):

mvn eclipse: eclipse

People who don’t use Maven but encounter this problem can right-click on the source folder and mark it as the source folder using “Build Path → Use as Source Folder”.

+7
source

Source: https://habr.com/ru/post/1482968/


All Articles