Saturday, February 8, 2014

How to debug Maven Applications in Intellij IDEA

Before I start, I would like to emphasize that this article is based on a Java console application and you need to make minor justifications in order to make it work for web apps in general.

I am assuming that you have a maven project (check out Getting Started with Maven) to make sure that project structure is valid.

To be able to debug a maven application, you need to set a Maven Debug Configuration in your Intellij IDEA project. If you do not know anything about existence of such thing, do not be scare as I will follow you through the steps.

First, in order to create a maven debug configuration, go to Run and click on Edit Configurations:

After that the Run/Debug Configuration window will pop up. Click on the "+" sign at the top-left part of the window, find Maven and click on it:

Now, you will see your Maven Configuration window. You can set a name  for it based on the goal of this debug or even name of the project. Just right below the name textbox, there are three tabs: Parameters, General and Runner. For this tutorial, we stick with the project settings options for the last two tabs and just consider the options inside the first Tab. As you can see in the following screen capture, the project directory has already been set for you. The most important task here is to set the command line of this configuration plus the profile of which you would like to debug your application.

Since we have a console application here, we will use Exec Maven Plugin which exists in Maven version 1 onwards.

exec:java -Dexec.mainClass=MainClass -Dexec.args=args

The -Dexec.mainClass will be set to the entry point of the application, here is the class with the main method, and -Dexec.args will be a set of arguments which will be passed to that main method. Here is an example:

exec:java -Dexec.mainClass=TopologyMain -Dexec.args=src/main/resources/words.txt

Now after you have set your debug breakpoint, set your Maven configuration in the dropdown of Select Run/Configuration and click on Debug (Or alternatively, go to Run and click on Debug and in the new window, select your Maven Config file):

After that, the Exec Plugin will compile your code and detach to the debugger process, like the following:

Happy Debugging your Maven Code!


  1. Thanks! It worked like a charm.

  2. Wow. This really made my day. Thanks a lot!
    JQuery Training JQuery Training Javascript JQuery Online Training

    JQuery Online Training JQuery Online Training Javascript Online Training JQuery Training

    JavaScript Training Courses

  3. Excellent post, short and sweet. Thanks a lot.

  4. hello this is good post thanks it will be great help for me.
    kajal hot

  5. Very nice post here and thanks for it .I always like and such a super contents of these post.Excellent and very cool idea and great content of different kinds of the valuable information's.
    Best Devops Training in pune
    Data science training in Bangalore

  6. Really you have done great job,There are may person searching about that now they will find enough resources by your post
    Best Devops training in sholinganallur
    Devops training in velachery
    Devops training in annanagar
    Devops training in tambaram

  7. Thanks for splitting your comprehension with us. It’s really useful to me & I hope it helps the people who in need of this vital information. 
    Thanks for splitting your comprehension with us. It’s really useful to me & I hope it helps the people who in need of this vital information. 

  8. Thanks for the good words! Really appreciated. Great post. I’ve been commenting a lot on a few blogs recently, but I hadn’t thought about my approach until you brought it up. 
    python Course in Pune
    python Course institute in Chennai
    python Training institute in Bangalore

  9. Thanks for your informative article, Your post helped me to understand the future and career prospects & Keep on updating your blog with such awesome article.
    Selenium training in Chennai
    Selenium training in Bangalore
    Selenium training in Pune
    Selenium Online training

  10. I think this is the best article today. Thanks for taking your own time to discuss this topic, I feel happy about that curiosity has increased to learn more about this topic. Keep sharing your information regularly for my future
    apple service center chennai
    apple service center in chennai
    apple mobile service centre in chennai
    apple service center near me