且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Eclipse Maven-代码完成失败“此编译单元不在Java项目的构建路径上"和“下载索引失败";错误

更新时间:2023-09-17 19:43:22

一个Maven项目(取决于它是Web类型还是其他项目)的结构如下:

A maven project (depending on whether it is type of a web or some other project) has structure like below:

为了使代码完成工作并按照下面的红色所述,请确保在您的 MyProject-war 项目(而不是 MyProject中的项目)中打开并修改Java文件. > MyProject-war 项目.

In order to get your code completion working and as explained in the red below, make sure you open and modify java file in your MyProject-war project, not the one in your MyProject > MyProject-war project.

在编辑器中打开这两个文件时,您会看到其中一个带有粗体"J",而另一个则在其选项卡中具有一个空心的"J",如下所示:

When you open these two files in the editor, you will see that the one has bold "J" in it, while the other one has a hollow "J" in its tab like below:

以粗体显示"J"的代码将具有适当的代码补全.您应该能够键入诸如String之类的东西.或yourObject.并完成代码.

The one with "J" in bold will have proper code completion. You should be able to type things like String. or yourObject. and get code completion.

带有空心"J"的代码不会显示代码完成,但会向您显示上面的信息和错误.

The one with hollow "J" wont show code completion but will show you the info and error above.