Eclipse报错: “this compilation unit is not on the build path of a java project”,同时按住Ctrl左击不跳转问题

时间:2023-02-05 17:47:44

问题情境描述:我用在eclipse官网下载最新的eclipse(Mars2版)64位,用eclipse自带的git插件导入gitbli上的maven项目,系统和eclipse中的tomcat(8.0)、JDK(1.7)、maven(3.3.9)配置完毕。

发现按住Ctrl左击选中的变量,不跳转!!!

问题初探:网上也查了,说是buildpath问题,按照百度的步骤说明试过了,还是没解决问题

后来, 右击变量——Declarations——Hierarchy,报错:this compilation unit is not on the build path of a java project

这才找到问题根源。百度之

在http://*.com/questions/2206572/eclipse-this-compilation-unit-is-not-on-the-build-path-of-a-java-project解决问题

原因是新安装的eclipse缺少某个组件,在.project文件添加

<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
解决!!!



解决后 .project 文件是这样的:

  <projectDescription>
...
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildspec>
...
...
...
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
...
</projectDescription>