Issues with maven project running in eclipse, not recognized as Java project

Lowell picture Lowell · May 31, 2011 · Viewed 69.8k times · Source

I've imported an existing maven project into Eclipse. I tried to set up the configurations for a JUnit test, and my project wouldn't come up as a testable project. When I typed in the project name manually, I was given the message:

Specified project is not a java project

I've also noticed that when typing code and trying to call a method e.g. "System.out" a message pops up when I type the period, saying:

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

Additionally, there are no actions available when I right click the project and navigate to Build Path.

Having looked this up on here and elsewhere, I've followed the following pieces of advice, without success:

I've verified the existence of .project and .classpath files

I've looked in the .project file and verified the inclusion of a javanature

I've run mvn eclipse:eclipse

I've right-clicked the project in the PackageExplorer > Maven > Update Project Configuration

Java is not listed as a project facet but I'm not sure I should mess with that because I've tried clicking that, and that caused the entire project to be filled with errors (I think related to build path, but I can't quite remember). Removing Java as a facet didn't get rid of the errors and I had to re-import the project from scratch.

Sorry if any of this is vague, and thanks for the help.

I'm using m2eclipse.

EDIT: Problem was solved simply by deleting the project from my workspace, deleting all .project, .classpath files and .settings folders, and re-importing. I don't know why it didn't work the first time.

Answer

Sean Patrick Floyd picture Sean Patrick Floyd · May 31, 2011

I've run mvn eclipse:eclipse
I've right-clicked the project in the PackageExplorer > Maven > Update Project Configuration

Those two should be mutually exclusive. Either you manage a project from the outside using eclipse:eclipse or from the inside using m2eclipse. Don't mix them.

Possible cause of the problem:

The packaging is POM (perhaps this is the root of a multi-module project, in which case you have to import the module projects). m2eclipse doesn't add the Java nature to POM projects (nor does eclipse:eclipse, btw)