此编译单元不在 Java 项目的构建路径上
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25401124/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
This compilation unit is not on the build path of a Java project
提问by Милош Керкез
When I try to use ctrl+space
this error is shown:
当我尝试使用ctrl+space
此错误时显示:
This compilation unit is not on the build path of a Java project.
I see that there are similar topics but my work environment is Eclipse and i pull my project from Git (I import project as general project) and i use Apache Ant. Can anyone help me?
我看到有类似的主题,但我的工作环境是 Eclipse,我从 Git 中提取我的项目(我将项目作为一般项目导入)并使用 Apache Ant。谁能帮我?
采纳答案by Loganathan Mohanraj
Since you imported the project as a General Project, it does not have the java nature and that is the problem.
由于您将项目作为常规项目导入,因此它不具有 java 性质,这就是问题所在。
Add the below lines in the .project file of your workspace and refresh.
在工作区的 .project 文件中添加以下行并刷新。
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
回答by Shaleen Agarwal
Go to Project-> right Click-> Select Properties -> project Facets -> modify the java version for your JDK version you are using.
转到项目-> 右键单击-> 选择属性-> 项目构面-> 修改您正在使用的JDK 版本的java 版本。
回答by kumar
If it is a Maven project then sometimes re-importing of it helps:
如果它是一个 Maven 项目,那么有时重新导入它会有所帮助:
- Right-click the project in the Project Explorer and choose Delete.
- File > Import... > Maven > Existing Maven Projects > Next > Root Directory > Browse your project from Disk.
- 在 Project Explorer 中右键单击该项目并选择 Delete。
- 文件 > 导入... > Maven > 现有 Maven 项目 > 下一步 > 根目录 > 从磁盘浏览您的项目。
Hope it will resolve the issue.
希望它能解决问题。
回答by Pradeep Anchan
Another alternative to Loganathan Mohanraj's solution (which effectively does the same, but from the GUI):
Loganathan Mohanraj 解决方案的另一种替代方案(有效地执行相同的操作,但来自 GUI):
- Right-Click on your project
- Go to "Properties"
- Choose "Project Natures"
- Click on "Add"
- Choose "Java"
- Click "Apply and Close"
- 右键单击您的项目
- 转到“属性”
- 选择“项目性质”
- 点击“添加”
- 选择“Java”
- 点击“应用并关闭”
回答by Pavan
Add this to .project file
将此添加到 .project 文件
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>framework</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
</natures>
</projectDescription>
回答by Jero Dungog
For those who still have problems after attempting the suggestions above: I solved the issue by updating the maven project.
对于尝试上述建议后仍有问题的人:我通过更新 maven 项目解决了该问题。
回答by pixel
In my case, I have Eclipse Maven project. I had the same issue and I posted detailed explanation of the issue and answer here Eclipse Maven - Code Completion fails "This compilation unit is not on the build path of a Java project" and "Failed to Download Index" Error
就我而言,我有 Eclipse Maven 项目。我遇到了同样的问题,我发布了问题的详细解释并在此处回答 Eclipse Maven - 代码完成失败“此编译单元不在 Java 项目的构建路径上”和“无法下载索引”错误