by Orlando Pagano

Using Remote JVM Debug in Intellij IDEA

Sometimes simple debug log messages are not enough. In order to debug a packaged jar app, we can pass a few arguments in a q2 shell script.

  • Open the -/src/dist/bin file in your project and look for the last line containing -jar @jarname@ "$@"
  • Replace that line with the following one: -jar -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005 @jarname@ "$@"
    • Start jPOS app using -/src/dist/bin/q2

NOTE: The argument address will configure the port on which debugger will listen.

To connect to debugger from Intellij IDEA:

  • Open Run/Debug Configurations
  • Add new Remote
  • Set Debugger mode to Attach to remote JVM
  • Set Host to localhost and port to the value configure above: 5005
  • Click OK
  • Choose your Run/Debug configuration and click Run.

IDEA Remote Configuration

Now you can place breakpoints in your code and debug.


Using Application in Intellij IDEA

This example depicts debugging the project mastercard-cas, but the configuration is almost identical for the others.

Screen Shot 2024-03-08 at 16 07 26

Screen Shot 2024-03-08 at 15 29 14

Build and Run:

  • Java: Java 11 was selected for this case, but you can choose the necessary version for your project.
  • -cp: Select the module where the java files are located
  • org.jpos.q2.Q2: Point to the jPOS main class
  • nohup: Keep jPOS running
  • Working Directory: Indicate the folder path where deploy files are located; they can be found in the build/install folder.

Before Launch:

Clicking on Modify options allows you to add tasks before launching.

Screen Shot 2024-03-08 at 15 30 50 Screen Shot 2024-03-08 at 16 01 56

  • Build: By default
  • Remove Shutdown: Prevent jPOS from shutting down immediately after starting by removing the deployment shutdown file.
  • Command: -f deploy/shutdown.xml
  • Working Directly: Folder path where deploy files are located

Screen Shot 2024-03-08 at 15 31 44

  • Gradle Tasks: You can add extra Gradle tasks before running jPOS.

Screen Shot 2024-03-08 at 15 32 14

Now, you can place breakpoints in your code and debug.

Screen Shot 2024-03-08 at 15 40 51

You will see something similar to this in the Debug console:

Screen Shot 2024-03-08 at 15 41 27

Have fun!


Other posts