Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 423
Lowell Avatar asked May 31 '11 19:05

Lowell


People also ask

How do I add a Java project to a Maven project in Eclipse?

In your eclipse just right click on Java Project and click Configure and you should see “ Convert to Maven Project ” option. You should see dialogue like this below. Just add “ Name ” and you should be all set. Don't forget to add your all custom dependencies in pom.

What is the difference between Java project and Maven project in Eclipse?

Eclipse internal build (Eclipse's Build Project or Build All or Clean) and Maven/Ant build basically do the same thing which means that they both will compile the source code file. Now an obvious difference is that Eclipse internal build will not generate EAR, WAR etc. files for you, which you do using ANT/Maven.

Can Maven be used for non Java projects?

Can Maven Be Used For Non-Java Projects? Yes. There are hundreds of archetypes for Maven, ranging from Java web application development to eBook publishing.


3 Answers

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)

like image 80
Sean Patrick Floyd Avatar answered Sep 26 '22 05:09

Sean Patrick Floyd


Make sure if you have M2 plugin in Eclipse, you have Maven 2.7 above installed in your system.

After that run mvn eclipse:clean then mvn eclipse:eclipse.

.classpath and .project will be created in your project folders. Everything should be fine.

like image 41
Zeta Avatar answered Sep 26 '22 05:09

Zeta


pls follow the below website.. Right click on the project, go to Properties, then select Project Facets. this will convert it to a java/dynamic web projects for the use.

like image 26
Syam Avatar answered Sep 22 '22 05:09

Syam