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):

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”.
source share