Remote Debugging on Cloud Foundry
As we know that everything is moving to Cloud. And it has become a bottleneck for a developer to debug the application/ code on Cloud. In this article I will share how you can debug your applications directly deployed on Cloud Foundry.
- IntelliJ IDEA : I would recommend community version if you don’t have a license.
- Application should be deployed on Cloud Foundry.
- You should have the same code base in local, which is deployed on Cloud Foundry.
- Add below property in your mta.yaml for your module under property section:
- JBP_CONFIG_JAVA_OPTS: “[from_environment: false, java_opts: ‘-Xms1300M -XX:NewSize=950M -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=8000,suspend=n’]”
- Open the command prompt (if you are using windows)/ Terminal(in case of Linux/Unix).
- Login to Cloud Foundry.
- cf login -a https://api.cf.sap.hana.ondemand.com (Canary Landscape).
- cf login -a https://api.cf.eu10.hana.ondemand.com (Live Landscape).
- Navigate to your space where your application is deployed.
- You can use this command to navigate: cf target -o <organisation name> -s <space name>
- After successfully navigating to space, you need to enable the ssh-tunnel for the application you want to debug.
- cf enable-ssh <application name>
- Just to be sure, run the below command to see whether ssh is enabled for your application or not.
- cf ssh-enabled <application name>
- Restage your application.
- cf restage <application name>
- After successfully restaging the application run the below command.
- cf ssh -N -T -L 8000:localhost:8000 <application name>
- Open IntelliJ IDEA and import your project.
- Click on the Add Configuration to the top right corner as show in the picture below.
- Now click on the “+” button and choose “Remote”.
- After clicking on Remote you will another window. Set the pot as “8000” and “main” in “Use module classpath”.
- Now click “Ok” and Click on Debug icon on the top right corner.
- After clicking on the debug icon, you will see “Connected ” in the console of IntelliJ.
- Put the debug points in the desired file.
Now you are ready to debug your application. You can open your application and you will get a hit on your breakpoints.
Note: Please let me know if you are facing some issues.