Thursday, January 14, 2010

Solving "the resource is not on the build path of a java project" error in Eclipse

Hey guys,
Encountered this problem while importing any existing project and trying to check the references of any class used or trying to do some java features related stuff in eclipse?
Here is the solution:
Go to the .project file in the project. You will see this file in the Navigator view. Then replace this existing code


<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
    <name>YOUR PROJECT NAME</name>
    <comment></comment>
    <projects>
    </projects>
    <buildSpec>
    </buildSpec>
    <natures>
    </natures>
</projectDescription>




in the .project with this one

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
 <name>YOUR PROJECT NAME</name>
 <comment></comment>
 <projects>
 </projects>
 <buildSpec>
  <buildCommand>
   <name>org.eclipse.jdt.core.javabuilder</name>
   <arguments>
   </arguments>
  </buildCommand>
  <buildCommand>
   <name>org.eclipse.wst.common.project.facet.core.builder</name>
   <arguments>
   </arguments>
  </buildCommand>
  <buildCommand>
   <name>org.eclipse.wst.validation.validationbuilder</name>
   <arguments>
   </arguments>
  </buildCommand>
 </buildSpec>
 <natures>
  <nature>org.eclipse.wst.common.project.facet.core.nature</nature>
  <nature>org.eclipse.jdt.core.javanature</nature>
  <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
  <nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
 </natures>
</projectDescription>


Refresh the project and the thing starts working :)