Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse says package declaration does not match expected package ""

Tags:

eclipse

maven

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 Project View

like image 624
Chetan Avatar asked May 27 '13 12:05

Chetan


1 Answers

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'.

like image 174
rethab Avatar answered Oct 15 '22 14:10

rethab