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

37,419

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.

Share:
37,419
Ssam
Author by

Ssam

HI ! ^_^ I am a developer in korea. My current major job is that developing CTI solution such as IVR system and Call management system that provides customer with call service. It's called "CallCenter" so nowdays I study various technologies~ and I want to be a very exceptional expert as a develpoer futhermore as a expert overall IT area ^^ Please share your knowledge , know-how and your skill ^_^ I also , If I've seen any question that I've known , of course, I'm gonna share my knowledge ^^ Ok thank you for reading my information. I hope you enjoy everyday~ ^_^

Updated on September 16, 2020

Comments

  • Ssam
    Ssam over 3 years

    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?

  • Aaron Franke
    Aaron Franke almost 7 years
    [ERROR] Could not find goal 'add-maven-repo' in plugin org.apache.maven.plugins:maven-eclipse-plugin:2.10 among available goals clean, configure-workspace, eclipse, help, install-plugins, myeclipse, myeclipse-clean, rad, rad-clean, remove-cache, resolve-workspace-dependencies, to-maven -> [Help 1]