欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

报错:this compilation unit is not on the build path of a Java project

程序员文章站 2022-06-23 15:02:48
...

this compilation unit is not on the build path of a Java project


从SVN上面检出了一个项目,在写代码的时候使用自动提示就报“this compilation unit is not on the build path of a Java project”错误,如图。

报错:this compilation unit is not on the build path of a Java project

 

查看Build Path 时也没有信息

报错:this compilation unit is not on the build path of a Java project

 

原因是检出的项目缺失了Java编译器。
解决方案如下:

关闭eclipse
找到项目文件夹内的.project文件
在文件内增加Java编译器相关内容:

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
    <name>检出的项目名称</name>
    <comment></comment>
    <projects>
    </projects>
    <!-- 检查有没有javabuilder,没有的话添加-->
    <buildSpec>    
        <buildCommand>    
            <name>org.eclipse.jdt.core.javabuilder</name>    
            <arguments>    
            </arguments>    
        </buildCommand>    
    </buildSpec>   
    <natures>
    <!-- 检查有没有javanature,没有的话添加-->
        <nature>org.eclipse.jdt.core.javanature</nature>    
        <nature>org.apache.ivyde.eclipse.ivynature</nature>    
    </natures>    
</projectDescription>

原项目project文件:

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
	<name>demo</name>
	<comment></comment>
	<projects>
	</projects>
	<buildSpec>
		<buildCommand>
			<name>org.eclipse.m2e.core.maven2Builder</name>
			<arguments>
			</arguments>
		</buildCommand>
	</buildSpec>
	<natures>
		<nature>org.eclipse.m2e.core.maven2Nature</nature>
	</natures>
</projectDescription>

修改后文件:

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
	<name>demo</name>
	<comment></comment>
	<projects>
	</projects>
	<buildSpec>
		<buildCommand>
			<name>org.eclipse.m2e.core.maven2Builder</name>
			<arguments>
			</arguments>
		</buildCommand>
		<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>


4.重开编译器项目即可重新编译为正常项目