Eclipse says package declaration does not match expected package “”

后端 未结 1 848
猫巷女王i
猫巷女王i 2021-01-01 03:37

I am using Maven to build my project. When I view it in Eclipse, it complains that

package declaration does not match expected package \"\"

相关标签:
1条回答
  • 2021-01-01 04:15

    Eclipse needs to recognize a certain folder as a 'Source Folder' in order to correctly interpret the contents as Java source files.

    Typically, if you create a Java project, Eclipse creates one folder called 'src' and marks it as 'Source Folder'. If you are dealing with a default Maven project setup, however, Eclipse will not automagically recognize 'src/main/java' as a source folder (unless you are using a plugin of course).

    If you are not sure whether Eclipse sees your folder as a 'Source Folder' or just a regular folder, take look at the icons (note the small package symbol on the lower left corner):

    enter image description here

    Since you are, as you stated, working with Maven, you should either use a Maven plugin for Eclipse or have Maven generate the required meta-files for Eclipse. This can be done with the command (generates .classpath and .project files):

    mvn eclipse:eclipse

    People who are not using Maven, but face this issue, can right-click on their source folder and mark it as source folder with 'Build Path -> Use as source folder'.

    0 讨论(0)
提交回复
热议问题