Monday

How to Set up, Run and Debug Maven Project in Eclipse

In newer versions of Eclipse, Maven is a first class citizen - it comes with Eclipse!!! The following demonstrates how to create, run and debug Maven projects in Eclipse 2018 ( with embedded Maven 3.5).

To create a Maven project, simply click the menu: "File"-"New"-"Other"

Select "Maven" - "Maven Project", and continue clicking "Next" until it asks you to enter group id and artifact id as shown below:

Enter both Group id and Artifact id, and click "Finish" - that's it!!! You have a Maven project.

To add more dependencies, just open pom.xml and add dependencies into "dependencies" xml element. This article is not about Maven so I won't go into details.

The default main Java class is App.java when you follow these steps to create the project. To run the project, find the main class in Eclipse project explorer and right click, then "Run As" - "Java Application".

If it requires more parameter to run, or if you want to include more Maven goals, then use Run configuration menu by going to menu "Run" - "Run Configuration", then create new launch profile. You need to enter base directory ( workspace location) and goals etc. Then click "Run". You may skip tests as well.

Finally, to debug the Maven project, set breakpoint in your source code as you normally do in a typical Java Project, then go to menu "Run" - "Debug Configuration", select the previously created lunch profile and click debug, as shown below:





7 comments:

Камков Вячеслав said...

Great instruction! Thanks a lot!

Anonymous said...

Good work!

Anonymous said...

Hey, that was really helpful :)
Thanks. . .

Anonymous said...

Great! Very helpful & straightforward!

Anonymous said...

that was really helpful :)
Thanks. . .

Anonymous said...

Thanks a lot.
Could you also tell me how to set it if i want to debug on 2 maven projects of which one is dependent on other.

Azim Hawaldar said...

I am getting this error. No goals have been specified for this build. You must specify a valid lifecycle phase . I know a goal has to be set for maven.. can you please let me know how to set a maven goal while running as a remote application