Caroh
Caroh

Reputation: 113

Remote debugging of Bluemix CF Java buildpack application

I have a standalone java application deployed on IBM Bluemix as Cloud Foundry Java buildpack.

Is there a way to perform remote debugging on it in Eclipse?I could find only docs for remote debugging of Java Liberty buildpack applications.

Upvotes: 0

Views: 663

Answers (2)

Shiva
Shiva

Reputation: 6885

The socket listen way mentioned in the other answer is certainly convenient, but expects you to have a public IP assigned to your debug machine(or you have to configure some port forwarding on your router). This might not always be possible.

So the another way to do it is enable debugging on your Java app and use ssh port forwarding to connect to the app instance. Following are the steps

  1. Enable java debugging by setting environment variable JBP_CONFIG_DEBUG with value {enabled: true} and restarting the application.
  2. Set up the SSH tunnel for the debug framework via JDWP

    cf ssh -N -T -L 8000:localhost:8000 <APP_NAME>

  3. After the ssh tunnel is opened, you use the Socket Attach debug type from eclipse on localhost:8000

Prerequisites before cf ssh: cf api, cf login, cf target

Upvotes: 2

opiethehokie
opiethehokie

Reputation: 1912

There are some instructions in the Java buildpack documentation at https://docs.cloudfoundry.org/buildpacks/java/java-tips.html#debugging

  1. Open your project in Eclipse.
  2. Right-click on your project, go to Debug as and pick Debug Configurations.
  3. Create a new Remote Java Application.
  4. Make sure your project is selected, pick Standard (Socket Listen) from the Connection Type drop down and set a port. Make sure this port is open if you are running a firewall.
  5. Click Debug.

The debugger should now be running. If you switch to the Debug perspective, you should see your application listed in the Debug panel and it should say Waiting for vm to connect at port.

Next, push your application to Cloud Foundry and instruct Cloud Foundry to connect to the debugger running on your local machine using the following instructions:

  1. Edit your manifest.yml file. Set the instances count to 1. If you set this greater than one, multiple applications try to connect to your debugger.
  2. Also in manifest.yml, add the env section and create a variable called JAVA_OPTS.
  3. Add the remote debugger configuration to the JAVA_OPTS variable: -agentlib:jdwp=transport=dt_socket,address=YOUR-IP-ADDRESS:YOUR-PORT.
  4. Save the manifest.yml file.
  5. Run cf push.

Upon completion, you should see that your application has started and is now connected to the debugger running in your IDE. You can now add breakpoints and interrogate the application just as you would if it were running locally.

Upvotes: 1

Related Questions