Eclipse "this compilation unit is not on the build path of a java project"

EclipseSvnBuildpath

Eclipse Problem Overview


I can't get autocompletion to work in Eclipse.

I'm working on the project on svn. I set up the project in Eclipse by going into

File -> Import -> Checkout As a Project -> New Project Wizard.

I chose Enterprise Java Application. Everything seemed to work fine except instead of autocompletion working as I expected I got a popup dialog displaying the message

> This compilation unit is not on the build path of a java project.

I've Googled it and everyone says that the project must be a Java project, but it is! What is the problem?

Update

The catalog structure on svn looks like this:

-Project_name
  -application
     -META-INF
       application.xml
       MANIFEST.MF
  +build
  +db
  +deploy
  +dist
  +lib
  +properties
  +script
  -src
     -META-INF
        someother.xml (datasource info)
        persistence.xml
        folder hierarchy with source files (should be package)
  -web
     some folders
          .
          .
     files
       .
       .
     -WEB-INF
        faces-config.xml
        jboss-web.xml
        web.xml
     build_win.xml

How do I tell Eclipse where the source files folder, application.xml, and other configuration xml files are?

Eclipse Solutions


Solution 1 - Eclipse

When you have a multimodules maven project under a parent project, make sure you're not editing the file in the maven parent project.

Solution 2 - Eclipse

What I did to make one of my projects to check out properly is by

  1. Import your project from svn

       file-->import-->SVN-Checkout Projects From SVN
    
  2. Find your Project and then in the "Check Out As" dialogue make sure you have the radio button selected "Check out as a project configured using the New Project Wizard"

  3. Go through regular steps.

The wizard pulls the project properly and then setups your eclipse....

without using the wizard I find that all hell breaks loose.....

Hope this helps...

Solution 3 - Eclipse

This is what was missing in my .project file:

	<projectDescription>
		...
		<buildSpec>
			<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>

Solution 4 - Eclipse

I have this issue from time-to-time and often it's because the project wasn't marked as a java project. You can change this by going to the properties for the project > Project Facets > and selecting java. You may then need to properly configure that project, but this is probably part of the problem

Solution 5 - Eclipse

I also had this problem after converting my java project into a maven project. I solved it as follows:

Right click on your project ->Project Facets -> click on Java, then Apply.

Solution 6 - Eclipse

Did you have your .project file in your folders?

I got the same problem. Than i realized that I didn't have the .project file.

Solution 7 - Eclipse

I might be picking up the wrong things from so many comments, but if you are using Maven, then are you doing the usual command prompt build and clean?

Go to cmd, navigate to your workspace (usually c:/workspace). Then run "mvn clean install -DskipTests"

After that run "mvn eclipse:eclipse eclipse:clean" (don't need to worry about piping).

Also, do you have any module dependencies in your projects?

If so, try removing the dependencies clicking apply, then readding the dependencies. As this can set eclipse right when it get's confused with buildpath sometimes.

Hope this helps!

Solution 8 - Eclipse

I did copy the .classpath and .project from another project and adjusted the values properly.

Close the project before editing those files, when you are sure they reflect the reality (your reality anyway), re-open the project in Eclipse.

The workspace is rebuilt and all should work from then on.

Solution 9 - Eclipse

in my case it's a maven project

delete the project from eclipse leaving the sources close eclipse delete from filesystem

.target/ .classpath .project .settings/ open eclipse Again Import Maven Projects

This solved the problem

Solution 10 - Eclipse

You may want to try running eclipse with the -clean startup option - it tries re-building eclipse's metadata of the workspace.

Solution 11 - Eclipse

mvn eclipse:eclipse

solved my problem

Solution 12 - Eclipse

Your source files should be in a structure with a 'package' icon in the Package Explorer view (in the menu under Window > Show View > Package Explorer or press Ctrl+3 and type pack), like this:

Java project in Eclipse

If they are not, select the folder containing your root package (src in the image above) and select Use as Source Folder from the context menu (right click).

Solution 13 - Eclipse

Here the steps for creating a source folder in eclipse.

  1. Right click on the project and go to properties
  2. Select "Java Build Path" from the properties dialog box
  3. Select the source tab and check that the source folders are correct if not click on the remove button to remove source folders, or the add button to add source folders.

You can control the order in which source folders appear in a project on order and export tab on the configure build path option.

Solution 14 - Eclipse

Had the same problem (but with Maven). The reason was incorrect choice of executor: my project used global settings that are not avilable from Embedded installation of Maven. Changed it to external (Window -> Preferences -> Maven -> Installations) and that fixed the problem.

Solution 15 - Eclipse

What i did is after importing the project from svn , deleted the project from workspace and imported it as a maven project from local . Then in preferences->maven->usersettings->in usersettings box gave path of settings.xml which will be in apache maven folder-> conf->settings.xml

and it solved the issue for me.

Solution 16 - Eclipse

Like the message says, is the file somewhere on the project's Java Build Path (e.g. a Source folder)?

Solution 17 - Eclipse

Had the same problem. Solution: Context menu -> Maven -> Enable dependency management

Do not know why that was lost, when checking out.

Solution 18 - Eclipse

I found that I was getting this error due to having my files, including my main class, outside of the .src folder.

Solution 19 - Eclipse

What worked for me was copping the .settings/ directory from another project.

Solution 20 - Eclipse

Run "mvn eclipse:eclipse" from terminal.

Solution 21 - Eclipse

If you're a beginner (like me), the solution may be as simple as making sure the parent folder that the file you're working in is a Java project.

I made the mistake of simply creating a Java folder, then creating a file in the folder and expecting it to work. The file needs to live in a project if you want to avoid this error.

Solution 22 - Eclipse

I had same issue after importing maven project consisting of nested micro services. This is how I got it resolved in Eclipse:

  1. Right Click on Project
  2. Select Configure
  3. Select "Configure and Detect Nested Projects"

Solution 23 - Eclipse

I solved this by adding projects in Java Build Path

Right click on the project -> properties -> java build path -> Add

enter image description here

Solution 24 - Eclipse

For example if there are 4 project and a root project, add the other child projects to build path of root project. If there is not selection of build path, add below codes to .project file.

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionl245c4lView Question on Stackoverflow
Solution 1 - EclipseredochkaView Answer on Stackoverflow
Solution 2 - EclipseLenn DollingView Answer on Stackoverflow
Solution 3 - EclipseAbhinavView Answer on Stackoverflow
Solution 4 - EclipseadamView Answer on Stackoverflow
Solution 5 - EclipseErandiView Answer on Stackoverflow
Solution 6 - EclipseyyyView Answer on Stackoverflow
Solution 7 - EclipseTommy GiovanelliView Answer on Stackoverflow
Solution 8 - EclipseAlexView Answer on Stackoverflow
Solution 9 - EclipseHuubView Answer on Stackoverflow
Solution 10 - EclipseRami CView Answer on Stackoverflow
Solution 11 - EclipseRenato VasconcellosView Answer on Stackoverflow
Solution 12 - EclipseFabian SteegView Answer on Stackoverflow
Solution 13 - EclipseamsView Answer on Stackoverflow
Solution 14 - EclipselaonixView Answer on Stackoverflow
Solution 15 - EclipseMazeen MuhammedView Answer on Stackoverflow
Solution 16 - EclipsenitindView Answer on Stackoverflow
Solution 17 - EclipseThomasView Answer on Stackoverflow
Solution 18 - EclipseTheMightyLlamaView Answer on Stackoverflow
Solution 19 - EclipsehausenView Answer on Stackoverflow
Solution 20 - EclipsePuppala MounikaView Answer on Stackoverflow
Solution 21 - EclipseTy HitzemanView Answer on Stackoverflow
Solution 22 - EclipseMuhammad AhmedView Answer on Stackoverflow
Solution 23 - EclipseShreevidya SView Answer on Stackoverflow
Solution 24 - EclipseOzturkView Answer on Stackoverflow