I am getting resource not on the buildpath of the project [duplicate]
Asked Answered
E

4

19

I am getting The resource is not on the buildpath of the project when I am trying to "Organize imports" or trying to access any class properties. I am building my project with ant.I tried to configure my buildpath in javabuilpath -> Projects but it is not showing me my src folder there.I am not able to use quick assist (ctrl + space) and class related properties because of the same reason and it does not show me any syntax errors also while i am writing my code.

please help me.

thanks

Election answered 2/3, 2011 at 16:50 Comment(0)
C
25

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.

Courtneycourtrai answered 27/3, 2012 at 17:58 Comment(2)
This answer is working in newer versions of Eclipse: https://mcmap.net/q/247427/-the-resource-is-not-on-the-build-path-of-a-java-projectEnhance
I have a maven project, and this led me to my answer which additionally included basically removing all source folders from my build path list, restarting Eclipse, and then running a [project node, right click]->Maven->Update Project... it seems to finally have worked (obviously this might not help you for countless reasons, but... YMMV)Sheave
S
0

Your src folder shouldn't appear in the Java Build Path -> Projects tab. Rather, it should appear under Source tab.

Samuel answered 2/3, 2011 at 16:55 Comment(1)
It is not appearing in the source tab. But when i am trying to add it using "Add Folder" at that time, it gives me location dependency errors.Election
E
0

Try imorting the class files as external jar.

Eurythmic answered 2/3, 2011 at 16:55 Comment(0)
A
0

What icon is used for the file? If it is an outline J eclipse doesn't recognize the file as being a source file of the project.

If so, you need to declare the parent folder of your package a source folder, i.e. if the path looks like ".../src/my/package/MyClass.java" the "src" must be declared a source folder (right click -> Build Path -> Use as Source Folder)

Ambo answered 2/3, 2011 at 17:8 Comment(2)
If I do this, The whole project becomes red with errors at all the lines. Please suggest.Faeroese
Well, what about checking what kind of errors you get? There might be another configuration error in your build path.Ambo

© 2022 - 2024 — McMap. All rights reserved.