I\'m working on a project that has lots of different Maven projects. I\'ve been doing a bunch of JUnit testing on these projects, and usually this goes well. I open up Eclipse
I know that this question was a long time ago...
I just resolved the issue by these 2 steps below.
mvn eclipse:eclipse will create necessary .project files which will add java nature & other properties to the project
I also tried all the approaches described in this thread. Modifying only .project is not enough because the maven libraries will not be used for building the project and the project build will fail. mvn eclipse:eclipse will create a long and useless .classpath without actually using m2e.
The easiest way is to create a new java project, convert it to the Maven project and open the .project and .classpath for this new project. Then make similar changes for the imported Maven project.
The important changes for the .project file have been described but in order to use the Maven dependencies in Eclipse something like this should be in the .classpath file
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
Using facets is not an option in this case because with facets Eclipse doesn't use m2e and the maven dependencies. Again the dependencies with facets have to be managed manually.
I tried all this with Eclipse 4.6.2 Neon.
My five cents... In my case I was 'losing' always the 'Java' nature of the project because the pom file was set to 'package as ear'. There was no error or warning message though, which would be nice to have. As soon as I changed the package to 'jar' I could set the nature of the project to Java and it is persisted.
It depends on the Eclipse project facet properties (if you are using Java EE), I suggest you right click on project properties and see which facet is defined for your project.
I faced the same problem(after importing pom.xml to eclipse,the project is not treated as a java one,and there is only "maven project builder" in project builders property,but no "java builder") in eclipse luna.
Re-importing maven project after deleting ".settings" folder and ".project" file did not work. Re-importing after a workspace switch worked for me.