Eclipse Maven-代码完成失败“此编译单元不在Java项目的构建路径上"和“下载索引失败";错误 [英] Eclipse Maven - Code Completion fails "This compilation unit is not on the build path of a Java project" and "Failed to Download Index" Error

查看:249
本文介绍了Eclipse Maven-代码完成失败“此编译单元不在Java项目的构建路径上"和“下载索引失败";错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了有关此主题的许多问题,有些有答案,但就我而言,没有一个问题可以帮助我解决此问题.至少,对我来说,没有一个人是蚀初学者.

I have found number of questions on this topic, some with answers but in my case not a single one was helping me resolve this problem. Or at least, not a single one that was clear to me, eclipse beginner.

但是我发现了我的问题,下面是它的描述.我还将发布答案.

But I figured out my problem and here is the description of it. I will also post answer.

我有一个Eclipse Maven项目.我注意到,如果打开.java文件并尝试通过键入类似obj.的文件进行编辑,则会出现错误"此编译单元不在Java项目的构建路径上.".错误,然后出现"无法下载索引"错误框,如下所示:

I have a eclipse maven project. I notice that if I open my .java file and try to edit it by typing something like obj., I get error "This compilation unit is not on the build path of a Java project." This error is then followed by the "Failed to Download Index" error box like below:

推荐答案

一个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.

这篇关于Eclipse Maven-代码完成失败“此编译单元不在Java项目的构建路径上"和“下载索引失败";错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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