Skip to Content
Technical Articles
Author's profile photo Achal Kansal

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.

Prerequisites:

  1. IntelliJ IDEA : I would recommend community version if you don’t have a license.
  2. Application should be deployed on Cloud Foundry.
  3. You should have the same code base in local, which is deployed on Cloud Foundry.

Steps:

  1. 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’]”
  2. Open the command prompt (if you are using windows)/ Terminal(in case of Linux/Unix).
  3. 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).
  4. Navigate to your space where your application is deployed.
    • You can use this command to navigate: cf target -o <organisation name> -s <space name>
  5. After successfully navigating to space, you need to enable the ssh-tunnel for the application you want to debug.
    • cf enable-ssh <application name>
  6. Just to be sure, run the below command to see whether ssh is enabled for your application or not.
    • cf ssh-enabled <application name>
  7. Restage your application.
    • cf restage <application name>
  8. After successfully restaging the application run the below command.
    • cf ssh -N -T -L 8000:localhost:8000 <application name> 
  9. Open IntelliJ IDEA and import your project.
  10. Click on the Add Configuration to the top right corner as show in the picture below.
  11. Now click on the “+” button and choose “Remote”.
  12. After clicking on Remote you will another window. Set the pot as “8000” and “main” in “Use module classpath”.
  13. Now click “Ok” and Click on Debug icon on the top right corner.
  14. After clicking on the debug icon, you will see “Connected ” in the console of IntelliJ.
  15. 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.

Happy Debugging.

Note: Please let me know if you are facing some issues.

 

Thanks,

Achal Kansal

Assigned Tags

      8 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Andrew Lunde
      Andrew Lunde

      If your needs tend toward Python and/or eclipse you might want to check out this post.

      The underlying mechanism of a reverse tunnel to a debugging server running local is the same.

       

      https://blogs.sap.com/2018/12/11/setting-up-a-python-development-environment-for-hana-with-remote-debugging/

       

      -Andrew

      Author's profile photo satish ch
      satish ch

      Hi Kansal,

      I have been working on debugging. If i try to connect to SAP, it is succeeding. But if i try with debugger i am seeing the following error:

      Error running ‘remote debug’: Unable to open debugger port (localhost:5005): java.net.ConnectException “Connection refused: connect”

       

      Thanks.

      Author's profile photo Achal Kansal
      Achal Kansal
      Blog Post Author

      Hi satish,

      You have to give 8000 as port number in intellj

      Thanks,

      Author's profile photo Sri Vidhya A N
      Sri Vidhya A N

      Hi Achal,

      We tried setting up remote debugging in IntelliJ and face the same error as above.

      Error running 'remoteDebugg': Unable to open debugger port (localhost:8000): java.net.ConnectException "Connection refused: connect"

      We tried with both options of DebuggerMode but still faced errors.

      Attach to Remote : Error running 'remoteDebugg': Unable to open debugger port (localhost:8000): java.net.SocketException "Connection reset" if chosen Attach to remote JVM

       Listen to Remote JVM: Error running 'remoteDebugg': Unable to open debugger port (localhost:8000): java.net.BindException "Address already in use: NET_Bind" if chosen Listen to remote JVM 

      P.N: In second case there was nothing running in the port.

       

       

      IntelliJ_Config

      IntelliJ_Config

      Author's profile photo Matheus Leao
      Matheus Leao

      What would be the analogous configuration for a Node application?

      Author's profile photo Anand Nidamanuru
      Anand Nidamanuru

      In the package json, under npm scripts, give the "start" command as "node --inspect <app.js>"

      You can find more details here 

      https://sap.github.io/cloud-sdk/docs/js/guides/remote-debugging

      https://blogs.sap.com/2020/11/23/debugging-nodejs-application-in-vscode-running-on-sap-cloud-foundry/

       

      Basically something like this

      "scripts": {
      
         "start": "node --inspect app.js",
      
      }
      
      app.js is your application starting point
      Author's profile photo Akanksha Priya
      Akanksha Priya

      Hello,

      The Application which I am trying to debug has the user variables maintained as=> JRE11. Currently remote debugging works in case of  java8 but I am not able to debug for this configuration. Do I need to follow some additional steps to debug for this app.

      Thanks

      Author's profile photo Darshan Rudresh
      Darshan Rudresh

      There is a slight change if you're using standard SAPMachine JDK and standard Java community     buildpack

      SAPMachine JDK: Has a standard debugger enabled by default. So we can control it whether to enable or disable it.

      This link may be helpful to please refer it

      https://help.sap.com/docs/btp/sap-business-technology-platform/debug-java-web-application-running-on-sapmachine?locale=en-US