84

I have been given a source folder (src) of a Java Project. I have created a .project file, kept it inside that folder and imported that project into Eclipse 3.6 through the Import Existing Projects into Workspace Option and added the required jars to it.

Now the problem is that when ever I do a Call Hierarchy on a Project, it displays an alert box saying "The resource is not on the build path of a java project"

Could somebody please let me know how to resolve this?

Please see the image here:

enter image description here

Thanks

Jasperan
  • 2,154
  • 1
  • 16
  • 40
Pawan
  • 31,545
  • 102
  • 256
  • 434

16 Answers16

95

You can add the src folder to build path by:

  1. Select Java perspective.
  2. Right click on src folder.
  3. Select Build Path > Use a source folder.

And you are done. Hope this help.

EDIT: Refer to the Eclipse documentation

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
AbdulAziz
  • 5,868
  • 14
  • 56
  • 77
  • I have selected Java Perspective and Right Clicked on it , went to properties and selected java Build Path , from there on i lost , Any help ? – Pawan Feb 27 '12 at 12:37
  • 2
    As i mention don't go to the properties. I repeat, do the step 2 and 3. Ask me again if you find any difficulty. check the edited answer. – AbdulAziz Feb 27 '12 at 12:42
  • 5
    After Right clicking on the source , I could not find the Build Path – Pawan Feb 27 '12 at 12:48
  • Try this: Right click on the project name --> Open Properties --> Java Build Path --> Add Jars This opens and small window with all your jar files with the projects directory. Navigate to the jar files and select all the jar files. Hope this solves your problem. – AbdulAziz Feb 27 '12 at 13:02
  • @yyyi777 if this way didn't work for you my answer is the simple manual way of it. it is not long, try it. – Juvanis Feb 27 '12 at 13:11
  • @yyyi777 ok as mention deporter, right click on the existing src folder (not the one of your old one, but the one which is been created as you import your project) and go to build path > remove from build path. – AbdulAziz Feb 27 '12 at 13:15
  • This suggestion fixed the problem for me, sincere thanks Abdul – KomodoDave Aug 09 '12 at 09:46
  • 29
    There is no such thing as a `Build path` in the latest eclipse versions. – dtheodor Sep 07 '14 at 20:10
  • Try to re-import the project. – smwikipedia Nov 25 '14 at 14:49
  • This option was right where it's supposed to be in Eclipse Mars Java EE. – Noumenon Sep 10 '15 at 18:32
  • This answer is working http://stackoverflow.com/questions/9464998/eclipse-the-resource-is-not-on-the-build-path-of-a-java-project#28534656 – apm Sep 30 '16 at 13:07
  • This answer is working in newer versions of Eclipse: http://stackoverflow.com/a/18073458/618465 – Navigatron Oct 07 '16 at 08:54
  • does adding source to build path have any effects ? because my source will be keep changing and tehre are multiple projects in the eclipse do I need to add only SRC? – Juke Sep 10 '19 at 16:52
19

I am trying to set up a dynamic web project using Eclipse and its Maven plugin. I am selecting maven-archetype-webapp and am facing the same problem (which I run into when trying to automatically produce getters and setters for some attributes).

My way around this was to right-click on the project, select Build Path --> Configure Build Path and then remove a weird exclusion filter "Excluded:**" which I found under the entry /src/main/resources.

Jasperan
  • 2,154
  • 1
  • 16
  • 40
pkaramol
  • 16,451
  • 43
  • 149
  • 324
15

Recently I met a similar problem. When importing a project without a .project file, a default empty .project file was generated without builders. Here is an example .project to make it work.

<buildSpec>
    <buildCommand>
            <name>org.eclipse.jdt.core.javabuilder</name>
        <arguments>
        </arguments>
    </buildCommand>
</buildSpec>
<natures>
    <nature>org.eclipse.jdt.core.javanature</nature>
</natures>
Jasperan
  • 2,154
  • 1
  • 16
  • 40
Andrew
  • 784
  • 9
  • 15
  • Its worked for me, But accepted answer is not working anymore, I'm using Build id: 20130919-0819 – apm Sep 30 '16 at 13:06
12

In my case, I had a java project containing many subfolders, each containing its own src folder.

project
-subfolder
--src/main/java
-subfolder2
--src/main/java

There was no options available when I used the Build Path -> right click option, as outlined by other responses.

I had to go to Project -> Properties -> Project Facets and click convert to faceted project.

Then I got all the src folders added to the build path.

ulrich
  • 1,431
  • 3
  • 17
  • 46
7

It means your project isn't on the compilation path of Eclipse. If after the accepted answer the problem still persists, then you need to first place that project on the compilation path.

For that, you need to import the project again into your workspace.

Ermiya Eskandary
  • 15,323
  • 3
  • 31
  • 44
Ravish Rawat
  • 476
  • 2
  • 15
  • 48
7

I found a similar issue and fixed it by correcting the .project file. For a Java project the .project file must have the below tag within the natures tag

org.eclipse.jdt.core.javanature


Example of complete .project file

<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
    <name>SampleProjectName</name>
    <comment></comment>
    <projects>
    </projects>
    <buildSpec>
        <buildCommand>
            <name>org.maven.ide.eclipse.maven2Builder</name>
            <arguments>
            </arguments>
        </buildCommand>
        <buildCommand>
            <name>oracle.eclipse.tools.weblogic.sharedLibraryFrameworkValidator</name>
            <arguments>
            </arguments>
        </buildCommand>
    </buildSpec>
    <natures>
        <nature>org.eclipse.jdt.core.javanature</nature>
    </natures>
</projectDescription>
Jasperan
  • 2,154
  • 1
  • 16
  • 40
Amit
  • 438
  • 5
  • 5
4
  1. Delete project from workspace (Uncheck physical deletion of project from disk)
  2. go to project location and delete .project file
  3. Import the project again.
Sunil N
  • 41
  • 3
3

Using Eclipse Oxygen with a multimodule maven project make sure you're not editing the file in the maven parent project.

This caused the "Open Declaration', 'Open Type Hierarchy' and 'Open Call Hierarchy' to show the dreaded dialog in question. It would even mess with the autocomplete.

Make sure you are not editing the parent project and instead edit the child project to avoid the error.

jmehrens
  • 10,580
  • 1
  • 38
  • 47
2

Refactor the name of the folder src/main/resource to src/main/java.

Right click the project > Build Path > Use Source Folder.

Zachary Craig
  • 2,192
  • 4
  • 23
  • 34
sapkota
  • 21
  • 1
2

Right click on your project -> Properties -> Project facets -> Convert -> Select Java in the checkboxes -> Apply and Close

Now you should be able to see your hierarchy.

0

Looks like you created your Java class under src/main/resources instead of src/main/java

Kris
  • 719
  • 1
  • 11
  • 19
0

If you imported a project from external source with pom.xml after import, go to Project->Properties->Maven and enable Java EE - This will resolve the error

Shan
  • 75
  • 9
0

If you open a file while in a perspective other than Java on a new project that hasn't yet been built and then go back to the Java perspective, you can get this alert message. Close the file and open it back up while in the Java perspective and then retry. Then if that fails the other solutions already provided will be of help.

For example:

  • Import a project that is in a git repository
  • Open the git perspective
  • Open the Git Staging view
  • Right click on a Java source file and select Open Working Tree Version
  • Open the Java perspective.
  • Now the "normal" Java features may not work correctly. Note that the file path is a literal path to the work station not the workspace.
0

Seems you imported the project to your workspace from git and not from a local repository. To add a local repository project to the workspace do the following:

Click on project (demoApp) -> imports projects -> finish.

Jasperan
  • 2,154
  • 1
  • 16
  • 40
Mohd Qasim
  • 896
  • 9
  • 20
-1

All you got to do is move your Project folder under the Src, that is all, it is done. Let me know if any more questions.

-1

In my case the source folder wasn't specified correctly. To solve the problem :

  • Right click on project name in project explorer
  • Select Properties
  • Select Java Build Path
  • Select Source tab and inspect what is there. Make sure to Add Folder... and select the folder which is the root of your source files.

As a result, you will notice that your folder structure in the project explorer will be modified to display package icons and package names instead.

Pierre C
  • 2,920
  • 1
  • 35
  • 35