Search code examples
eclipsemaveneclipse-wtpmaven-jetty-plugin

How to import a Maven+jetty project to Eclipse as a Dynamic Web Project?


I have a Maven project that uses Jetty (pom), it can be run like this:

$ mvn jetty:run

Many developers want to debug it within Eclipse.

QUESTION: What is the most straightforward way to import the project into Eclipse in such a way that it can be debugged as a webapp?


MY ATTEMPT:

  1. Run mvn eclipse:eclipse or mvn eclipse:eclipse -Dwtpversion=1.5
  2. In Eclipse, define the M2_REPO variable pointing to your Maven directory, for instance /home/nico/.m2/repository
  3. Import > Existing project > Select the project directory > OK
  4. Check "Dynamic Web Project" then click "Further configuration available..." and enter in "web content" enter "src/main/webapp". You can not change it afterwards.

I feel it is not far from working, but problem: I don't see how to tell Eclipse where the jars are.
Is there a better solution than copying all needed jars from the Maven repository to src/main/webapp/WEB-INF/lib manually ?

Note: This question is rather similar but the accepted answer is only a single step of the process.


Solution

    1. Install Run Jetty Run
    2. Run mvn eclipse:eclipse
    3. In Eclipse, define the M2_REPO variable pointing to your Maven directory, for instance /home/nico/.m2/repository
    4. Import > Existing project > Select the project directory > OK
    5. Right-click on project > Debug as > Run Jetty

    Now the app will stop at your breakpoints, go step-by-step when you want, etc.