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!

47 comments:

  1. Thanks! It worked like a charm.

    ReplyDelete
  2. Excellent post, short and sweet. Thanks a lot.

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

    ReplyDelete
  4. 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

    ReplyDelete
  5. 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. 

    ReplyDelete
  6. 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

    ReplyDelete
  7. Excellent article, nice info, must say thanks for the information you added to this post. I appreciate your post and looking forward for more.


    ExcelR Data Science in Bangalore

    ReplyDelete
  8. Thank you for your post, I look for such article along time, today i find it finally. this post give me lots of advise it is very useful for me.
    date analytics certification training courses
    data science courses training

    ReplyDelete
  9. Attend The Python training in bangalore From ExcelR. Practical Python training in bangalore Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Python training in bangalore.
    python training in bangalore

    ReplyDelete
  10. I really enjoyed reading this post, big fan. Keep up the good work andplease tell me when can you publish more articles or where can I read more on the subject?






    BIG DATA COURSE MALAYSIA

    ReplyDelete
  11. Attend The PMP Certification From ExcelR. Practical PMP Certification Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The PMP Certification.
    ExcelR PMP Certification

    ReplyDelete
  12. I Love your article. You can visit my website : zipper widget pro

    ReplyDelete
  13. This is an awesome blog. Really very informative and creative contents. This concept is a good way to enhance the knowledge. Thanks for sharing.
    ExcelR business analytics course

    ReplyDelete
  14. please share the settings for the testng test.
    When i try the above mvn parameters I am getting error .
    Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.2.1:java (default-cli) on project dw-rco-test: An exception occured while executing the Java class. MainClass

    ReplyDelete
  15. Nice post. Thanks for sharing this useful information.
    Data Science Training in Hyderabad

    ReplyDelete
  16. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me..
    https://www.acte.in/angular-js-training-in-chennai

    ReplyDelete
  17. Thanks for giving me the time to share such nice information. Thanks for sharing.data science course in Hyderabad

    ReplyDelete
  18. I am impressed by the information that you have on this blog. It shows how well you understand this subject.
    Data Science courses

    ReplyDelete
  19. Thank you for sharing
    https://socialprachar.com/data-science-training-in-bengaluru/

    ReplyDelete
  20. Thanks for posting the best information and the blog is very impressive.python course in Bangalore

    ReplyDelete
  21. Thank you for excellent article.You made an article that is interesting. Nurture through nature

    ReplyDelete
  22. Attend the data Science Courses from AI Patasala. Practical data science Courses Sessions with Assured Placement Support from Experienced Faculty. AI Patasala Offers the Data Science Courses.
    Data Science Course with Placements in Hyderabad

    ReplyDelete
  23. I am very happy with your blog because I have read your entire blog. Your blog is very interesting .. Your style is also very beautiful.

    BA 1st Year Time Table 2022
    BA 2nd Year Time Table 2022
    BA 3rd Year Time Table 2022

    ReplyDelete
  24. Nice post! This is a very nice blog that I will definitively come back to more times this year! Thanks for informative post.
    cyber security course in malaysia

    ReplyDelete
  25. Hi buddies, it is great written piece entirely defined, continue the good work constantly. data analytics courses pune

    ReplyDelete
  26. drawingstudios.com What is mod APK or modded APK? ... Mod APKs are reworked copies of the original mobile apps that were distributed with them. Mod APKs are made to provide users ..

    ReplyDelete

  27. Hyderabad is a vital center for trade, the economy, tourism, technology, and development, and it does so with incredible beauty and pride. As one of the Best Immigration consultants in Hyderabad with a national reputation, GreenTree Immigration holds the city dear to our hearts and finds it to be an utter joy to live in.

    ReplyDelete