Thursday, 5 September 2013

Cool tip of the day: Maven & Eclipse ... importing projects

Today I attempted to import a project that had been written using MAVEN as its build process.
So I confidently when to the eclipse option to import existing maven projects ... all went well until I opened the project & tried to build it. when I saw this error:

Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-resources-plugin:2.4.3:resources (execution: default-resources, phase: process-resources)   pom.xml /test line 6    Maven Project Build Lifecycle Mapping Problem
This was not very welcome and the eclipse autofix options did not fix the issue.
So I turned to Slastdot & found a post (http://stackoverflow.com/questions/7638562/import-maven-project-to-eclipse-and-fix-the-errors) but the top solution to to do a project update did not work.

So to fix it I followed a secondary solution (after deleting the .project file previously created) ...


  1. Open the project folder in a command prompt;
  2. run command mvn eclipse:eclipse
  3. Open the project using eclipse;
  4. Set project properties "configure-->Convert to Maven Project"
My experience is that this works nicely.... ALMOST!

The issue is that eclipse may not correctly pick up the maven dependencies.
This is because the .classpath file does not include values on the paths as  follows "<attribute name="maven.pomderived" value="true"/>".

This for a simple project means that you needs to convert your .classpath file from this:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
  <classpathentry kind="src" path="src/test/java" output="target/test-classes" including="**/*.java"/>
  <classpathentry kind="src" path="src/main/java" including="**/*.java"/>
  <classpathentry kind="output" path="target/classes"/>
  <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
  <classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar"/>
</classpath>

to this:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
  <classpathentry kind="src" path="src/test/java" output="target/test-classes" including="**/*.java">
        <attributes>
            <attribute name="optional" value="true"/>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
  <classpathentry kind="src" path="src/main/java" including="**/*.java">
        <attributes>
            <attribute name="optional" value="true"/>
            <attribute name="maven.pomderived" value="true"/>
        </attributes>
    </classpathentry>
  <classpathentry kind="output" path="target/classes"/>
      <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
        <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>
</classpath>

Now this should pick up your MAVEN dependencies.

Other references:

  1. http://stackoverflow.com/questions/2037188/how-to-configure-eclipse-build-path-to-use-maven-dependencies
  2. https://groups.google.com/forum/#!topic/scala-ide-user/M9pMpZGD624

No comments:

Post a Comment