Ssam
Ssam

Reputation: 277

Compilation unit is not on the build path of a Java project

I joined an SVN server and checked out the source files a project from that server. In the Eclipse editors, when I hit Ctrl + Space, I got the following error message:

This compilation unit is not on the build path of a Java project

This compilation unit is not on the build path of a Java project

What should I do to solve this problem?

Upvotes: 9

Views: 39930

Answers (5)

This is due to the issue in build path .

If you had imported the project as Existing Maven project, do the following to resolve the issue.

Right click in the Package Explorer -> Maven -> Update project.

Or select the project in package explorer and perform Alt+F5 which is the shortcut for the maven project update.

Upvotes: 0

R.J. Davis
R.J. Davis

Reputation: 1

Follow these steps:

  1. Right click project in Eclipse. Select to Run AsMaven build...
  2. In Goals add eclipse:eclipse
  3. Select Run
  4. Wait for build to finish
  5. Right click project in Eclipse. Select Refresh

Upvotes: 0

kumar
kumar

Reputation: 451

Import project as maven project.

File-> import-> Maven-> Exiting Maven Project-> Next-> Root Directory-> Browse your project from Disk

Upvotes: 0

Raghav RV
Raghav RV

Reputation: 4076

Read this guide on how to use maven projects with eclipse

http://maven.apache.org/guides/mini/guide-ide-eclipse.html

Taken from the above link :

Reason why you get that notice :

Eclipse needs to know the path to the local maven repository. Therefore the classpath variable M2_REPO has to be set.

Solution

Execute the following command:

mvn -Declipse.workspace=<path-to-eclipse-workspace> eclipse:add-maven-repo

Restart your Eclipse IDE (if you already have it open) for this change to take effect. You can also define a new classpath variable inside eclipse: From the menu bar, select Window > Preferences. Select the Java > Build Path > Classpath Variables page

For Simple Projects :

If you have a simple java project which is made up of only one module, using eclipse is very simple. To generate the eclipse project files from your POM you execute the following command:

mvn eclipse:eclipse

If you have created or checked out the project with eclipse, you only have to refresh the project in your workspace. Otherwise you have to import the project into your eclipse workspace (From the menu bar, select File >Import >Existing Projects into Workspace). In the latter case the project (directory) should not be located in your workspace, because eclipse might come into trouble, especially if you want to use eclipse as the scm client.

For a more detailed explanation refer the above link.

Upvotes: 3

Rahul
Rahul

Reputation: 25

Execute mvn eclipse:eclipse on command line and once the build is successful, refresh your project in eclipse. This resolve the issue.

Upvotes: -1

Related Questions