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
- Start jPOS app using
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.
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.
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.
- 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
- Gradle Tasks: You can add extra Gradle tasks before running jPOS.
Now, you can place breakpoints in your code and debug.
You will see something similar to this in the Debug console:
Have fun!
Other posts
- 2024-09-06MUXPool Strategies
- 2024-08-26jPOS Extreme Performance
- 2023-12-22jPOS 2.1.9 has been released
- 2023-07-12Notes on JMeter with the ISO-8583 plugin
- 2023-01-02Implementing HA with jPOS components
- 2022-04-08jPOS Next
- 2022-01-24jPOS 2.1.7 has been released
- 2021-06-04jPOS-EE 2.2.7 has been released
- 2021-03-31jPOS 2.1.6 has been released
- 2020-12-06jPOS 2.1.7 has been released
- 2020-09-01BadSharedMemories