Eclipse: the Resource Is Not on the Build Path of a Java Project

I am getting resource not on the buildpath of the project

I just hit this problem myself, and it's baffling. You get it in a bunch of different places as you try and treat a Java file as, you know, a Java file but Eclipse hasn't figured out that it's actually a class within your project. The reason it doesn't know (or the reason it didn't know in my case) was because the directory hasn't been marked as a source directory for the project. So you need to tell the project configuration that the file is in a directory that holds source files. Here's how:

  1. Open your project's properties.

  2. Under "Java Build Path", click on the "Source" tab.

  3. Click "Add Folder..."

  4. Find the folder where you have the unrecognized java file. (In my
    case it was test->Java)

  5. Put a check by the folder. (I put it only by "java" and not by
    "test" given that the test folder holds a lot of other stuff.)

  6. Click ok, click OK again, perhaps refresh, and you should be good to
    go.

Understanding Eclipses' "The resource is not on the build path of a Java project" error message?

Refactoring operations, like many other java-specific operations, rely on the ability of the tooling to correctly parse the code in question. Generally, that means that:

  • The code has to be valid enough (syntax and grammar) for the selected element to the correctly parsed.
  • The java source file in question needs to be within a java project's source folder.
  • The build path must be correct and error free so that referenced classes and packages can be correctly identified.

This message is telling you that one or more of those conditions are not met.

Why does my eclipse project not have a build path?

It looks like you did not add Eclipse project metadata files to your source control system, so Eclipse doesn't know what your build path is or whether it is even a java project. You can see that the little folder on your dungeonworld project is missing the little 'j', which means Eclipse doesn't think it's a java project.

Go back to your other computer and look for the following files in your original project root...

  1. .project
  2. .classpath
  3. .settings/*

Make sure all of the end up in your source control system or nothing will work right.



Related Topics



Leave a reply



Submit