I am using Maven to build my project. When I view it in Eclipse, it complains that
package declaration does not match expected package ""
Maven is able to successfully build the project though.
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):
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'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With