问题
When I try to use ctrl+space
this error is shown:
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?
回答1:
Since you imported the project as a General Project, it does not have the java nature and that is the problem.
Add the below lines in the .project file of your workspace and refresh.
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
回答2:
If it is a Maven project then sometimes re-importing of it helps:
- 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.
Hope it will resolve the issue.
回答3:
Go to Project-> right Click-> Select Properties -> project Facets -> modify the java version for your JDK version you are using.
回答4:
Another alternative to Loganathan Mohanraj's solution (which effectively does the same, but from the GUI):
- Right-Click on your project
- Go to "Properties"
- Choose "Project Natures"
- Click on "Add"
- Choose "Java"
- Click "Apply and Close"
回答5:
Add this to .project file
<?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>
来源:https://stackoverflow.com/questions/25401124/this-compilation-unit-is-not-on-the-build-path-of-a-java-project