Here’s How to Actually Do It on Oracle Cloud (OCI) & Kubernetes.
Every Java developer knows that the JVM supports remote debugging via JDWP (-agentlib:jdwp=...). Yet when a weird bug appears in a cloud environment, what do we actually do?
We add log.info("HERE 1: value={}", x), commit, wait 10 minutes for CI/CD, check the logs, realise we logged the wrong variable, and repeat.
Almost nobody uses remote debugging in the cloud because it feels complicated: developers think they have to rebuild their Docker image with debug settings, open risky ports (5005) in their cloud firewall, or struggle with Kubernetes networking.
In reality, you don’t need any of that. With JAVA_TOOL_OPTIONS and an encrypted local tunnel (kubectl port-forward on OKE or ssh -L on an OCI Compute VM), you can attach IntelliJ IDEA directly to a running cloud container in under 2 minutes—without modifying your Dockerfile or exposing port 5005 to the internet.
As an Oracle ACE, I built a small Java 25 + Spring Boot 4 sandbox repository so you can try live cloud debugging hands-on right now on Oracle Cloud Infrastructure (OCI) (and it also includes manifests if you work with Red Hat OpenShift).
Two built-in mechanisms make cloud debugging effortless and secure:
JAVA_TOOL_OPTIONS: The JVM automatically picks up this environment variable at startup. You can toggle remote debugging on or off in your container runtime or Kubernetes deployment with a single environment variable change—zero image rebuilds.
Local Port Tunnelling: Port 5005 never needs an OCI Load Balancer, Ingress, or VCN Security List ingress rule. You tunnel localhost:5005 on your laptop directly to the container over your authenticated kubectl or ssh connection.
Step 1: Clone the Demo Project
The demo app exposes an order pricing endpoint (/api/orders/quote) with a classic bug: a 15% discount calculation that mysteriously returns a $0.0 discount.
git clone https://github.com/martin-ladecky/openshift-debugging.git cd openshift-debugging Look at the Dockerfile:
EXPOSE 8080 5005 ENTRYPOINT ["java", "-jar", "/app/app.jar"] There are no debug flags hardcoded into ENTRYPOINT. Instead, JDWP is configured through the JAVA_TOOL_OPTIONS environment variable at deployment time:
env: - name: JAVA_TOOL_OPTIONS value: "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005" Step 2: Deploy to Oracle Cloud Infrastructure (OCI)
You have two ways to run this demo on OCI (detailed in README-OCI.md):
Path A: Oracle Container Engine for Kubernetes (OKE)
The repository includes a ready-to-use OKE manifest in oci/oke-deployment.yaml.
1. Build and push the image to Oracle Cloud Infrastructure Registry (OCIR) (or any public registry):
# Format: <region-key>.ocir.io/<tenancy-namespace>/openshift-debugging:latest docker build -t fra.ocir.io/<tenancy-namespace>/openshift-debugging:latest . docker push fra.ocir.io/<tenancy-namespace>/openshift-debugging:latest 2. Deploy to your OKE cluster (after setting your image URL in oci/oke-deployment.yaml):
kubectl apply -f oci/oke-deployment.yaml kubectl rollout status deployment/openshift-debugging 3. Forward both HTTP (8080) and JDWP (5005) from the OKE pod to your laptop:
kubectl port-forward deployment/openshift-debugging 8080:8080 5005:5005 Path B: OCI Always Free Compute VM (Zero Cost, Never Expires)
If you want a permanent demo environment that never expires after 30 days and never idles containers to zero, spin up an OCI Always Free Compute VM (such as an Ampere A1 ARM64 instance or AMD Micro instance):
1. On your OCI Compute VM, build and start the container:
git clone [https://github.com/martin-ladecky/openshift-debugging.git](https://github.com/martin-ladecky/openshift-debugging.git) cd openshift-debugging docker build -t openshift-debugging:latest . docker run -d --name openshift-debugging \ -p 8080:8080 -p 127.0.0.1:5005:5005 \ -e JAVA_TOOL_OPTIONS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005" \ openshift-debugging:latest IMPORTANT
Notice
-p 127.0.0.1:5005:5005: this binds the JDWP debug port strictly to the VM's loopback interface. Even if someone accidentally opens all ports in your OCI VCN Security List, port 5005 cannot be reached from the outside internet!
2. On your laptop, tunnel local ports 5005 and 8080 securely over SSH:
ssh -L 5005:localhost:5005 -L 8080:localhost:8080 opc@<OCI_VM_PUBLIC_IP> (Bonus: Using Red Hat OpenShift—either on OCI or via the Red Hat Developer Sandbox? The repo also includes full OpenShift manifests in openshift/ and instructions in README.md using oc start-build and oc port-forward!)
Step 3: Verify JDWP Status & Trigger the Bug
With your kubectl port-forward or ssh -L tunnel active, query /api/debug/info to verify Java 25 and the JDWP agent inside the OCI container:
APP_URL="http://localhost:8080" curl -s "$APP_URL/api/debug/info" | jq { "application": "openshift-debugging", "podHostname": "openshift-debugging-6b8d7f9c4-x92lm", "javaVersion": "25.0.5+8-LTS", "jdwpEnabled": true, "jvmArguments": [ "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005" ] } Now trigger the pricing bug by requesting a quote for 2 laptops at $1200 with a 15% discount:
curl -s "$APP_URL/api/orders/quote?item=laptop&quantity=2&unitPrice=1200&discountPercent=15" | jq { "item": "laptop", "quantity": 2, "unitPrice": 1200.0, "discountPercent": 15, "subtotal": 2400.0, "discountAmount": 0.0, "finalTotal": 2400.0 } discountPercent is 15, yet discountAmount is 0.0. Instead of reading logs, let's attach IntelliJ IDEA directly to the container running in Oracle Cloud.
Step 4: Attach IntelliJ IDEA & Fix Variables In-Flight
1. Start the Debugger:
Open the project in IntelliJ IDEA. Select the preconfigured Remote OpenShift Debug (5005) configuration from the top-right dropdown (stored in .run/Remote OpenShift Debug (5005).run.xml), which connects to localhost:5005, and click Debug (🐞):
Connected to the target VM, address: 'localhost:5005', transport: 'socket' 2. Place a Breakpoint:
Open OrderPricingService.java and click the gutter on line 32:
double discountRatio = discountPercent / 100; 3. Step Through & Patch State Live in Oracle Cloud:
- Re-run the
curlrequest against/api/orders/quote. - Your local IntelliJ IDEA immediately pauses the HTTP thread executing inside your OCI container!
- Press F8 (Step Over) and inspect
discountRatio: integer division truncated15 / 100to0.0. - In IntelliJ's Threads & Variables pane, right-click
discountRatio-> Set Value... (F2), set it to0.15, and press F9 (Resume Program). - Check your terminal output—the OCI container finishes the request with the patched value and returns
"discountAmount": 360.0and"finalTotal": 2040.0!
Fixed server:
3 Cloud Debugging Tips Every Java Developer Should Know
Watch Out for Kubernetes Liveness Probes on OKE!
By default, IntelliJ breakpoints pause all JVM threads (Suspend: All). If you sit on a breakpoint in OKE (or OpenShift) for 30+ seconds, Kubernetes
/actuator/health/livenessprobes will time out and restart your pod mid-debug!The Fix: Right-click the red breakpoint dot in IntelliJ and switch Suspend from All to Thread. Only your HTTP request thread pauses while health-check threads keep responding normally.
1. Toggle Debugging On Any Running OKE Deployment Without Rebuilding
Need to debug a deployment that wasn't started with JDWP enabled? Turn it on dynamically with kubectl:
# Enable remote debugging (triggers a rolling pod restart) kubectl set env deployment/openshift-debugging \ JAVA_TOOL_OPTIONS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005" # Disable remote debugging when finished kubectl set env deployment/openshift-debugging JAVA_TOOL_OPTIONS- 2. Debug Startup Issues (suspend=y)
If your pod fails during Spring Boot startup, change suspend=n to suspend=y. The JVM will wait before executing main() until you connect your IDE over the port-forward tunnel:
kubectl set env deployment/openshift-debugging \ JAVA_TOOL_OPTIONS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:5005" Try It Yourself
Clone the repository and try remote debugging on Oracle Cloud Infrastructure (or Red Hat OpenShift):
GitHub Repository: https://github.com/martin-ladecky/openshift-debugging
Oracle Cloud (OCI) Guide: README-OCI.md
Red Hat OpenShift Guide: README.md

