Debugging in Maven?

前端 未结 8 1674
眼角桃花
眼角桃花 2020-11-28 02:56

Is it possible to launch a debugger such as jdb from Maven? I have a pom.xml file that compiles the project successfully. However, the program hangs somewhe

8条回答
  •  猫巷女王i
    2020-11-28 03:37

    If you don't want to be IDE dependent and want to work directly with the command line, you can use 'jdb' (Java Debugger)

    As mentioned by Samuel with small modification (set suspend=y instead of suspend=n, y means yes which suspends the program and not run it so you that can set breakpoints to debug it, if suspend=n means it may run the program to completion before you can even debug it)

    On the directory which contains your pom.xml, execute:

    mvn exec:exec -Dexec.executable="java" -Dexec.args="-classpath %classpath -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=1044 com.mycompany.app.App"
    

    Then, open up a new terminal and execute:

    jdb -attach 1044
    

    You can then use jdb to debug your program!=)

    Sources: Java jdb remote debugging command line tool

提交回复
热议问题