Eclipse说包装声明不符合预期的包装“ [英] Eclipse says package declaration does not match expected package ""

查看:153
本文介绍了Eclipse说包装声明不符合预期的包装“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Maven构建我的项目。当我在Eclipse中查看它时,它抱怨说


包声明不符合预期的包


Maven能够成功地构建项目。



解决方案

Eclipse需要识别某个文件夹作为源文件夹,以便将内容正确解释为Java源文件。



通常,如果创建一个Java项目,Eclipse会创建一个名为src的文件夹并将其标记为源文件夹。但是,如果您正在处理默认的Maven项目设置,Eclipse将不会自动识别src / main / java作为源文件夹(除非您正在使用插件)。



如果您不确定Eclipse是否将文件夹视为源文件夹或只是常规文件夹,请查看图标(请注意左下角的小包装符号):





正如你所说,正如你所说,使用Maven,你应该使用一个Maven插件给Eclipse,或者让Maven为Eclipse生成所需的元文件。这可以通过命令(生成.classpath和.project文件)完成:


mvn eclipse: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 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'.

这篇关于Eclipse说包装声明不符合预期的包装“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆