Maven project not being treated as Java in Eclipse

后端 未结 14 738
星月不相逢
星月不相逢 2021-02-05 04:30

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

相关标签:
14条回答
  • 2021-02-05 04:56

    I know that this question was a long time ago...

    I just resolved the issue by these 2 steps below.

    1. run cmd "mvn eclipse:eclipse" in the root directory of the project
    2. right-click on the project in eclipse then select "import as project"
    0 讨论(0)
  • 2021-02-05 04:57

    mvn eclipse:eclipse will create necessary .project files which will add java nature & other properties to the project

    0 讨论(0)
  • 2021-02-05 04:57

    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.

    0 讨论(0)
  • 2021-02-05 05:00

    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.

    0 讨论(0)
  • 2021-02-05 05:01

    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.

    0 讨论(0)
  • 2021-02-05 05:03

    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.

    0 讨论(0)
提交回复
热议问题