This topic explains how to configure Tanzu Platform to build your Java applications with debug enabled so that you can attach a debugger to inspect the applications while they are running.
Before you begin
Before you can deploy a Java application with debug enabled into a Space, you must:
-
Install Tanzu CLI v1.5.1 or later. See Installing the Tanzu CLI.
-
Log in to Tanzu Platform using the Tanzu CLI by running:
tanzu login
Overview of steps
The following provides an overview of the steps to configure the platform to build and run applications with debug enabled:
Create a custom build plan
Before developers can debug Java applications, a platform engineer must create a Project-level custom container app build plan so that applications deployed in the Project are built and run with debug enabled.
To create a custom build plan:
-
Set the Project that you want to support debug as the context:
tanzu project use PROJECT-NAME
-
Retrieve the default
ContainerAppBuildPlan
from the Project:KUBECONFIG=~/.config/tanzu/kube/config kubectl get containerappbuildplans.build.tanzu.vmware.com simple.tanzu.vmware.com -oyaml
-
Copy the output and paste it into a file named
tanzu-debug.yaml
. -
Make the following changes to
tanzu-debug.yaml
:- For
metadata.name
, update the value todebug.tanzu.vmware.com
. -
Delete the following fields under
metadata
:creationTimestamp
generation
resourceVersion
uid
-
In
spec.postBuildSteps
, add anamedTask
afterspring-boot.tanzu.vmware.com
calledtanzu-java-debug
.
- For
-
Apply
tanzu-debug.yaml
by running:KUBECONFIG=~/.config/tanzu/kube/config kubectl apply -f tanzu-debug.yaml
-
Create and allocate Spaces from this Project as required. Ensure that these Spaces are assigned to an Availability Target that has a single cluster.
VMware recommends that you assign developers their own Spaces so that they can iterate on applications without affecting other developers iterating on the same application at the same time.
Deploy an application
To deploy an application and connect the debugger:
-
Open the IntelliJ IDE.
-
Install the Tanzu Platform Developer Tools plug-in from disk and restart the IDE (one-time only). You can download the plug-in ZIP file from the Broadcom Support Portal.
The IntelliJ packaging format is ZIP. Do not unzip the file.
-
Open your source code in the workspace.
-
Open an IDE terminal window and run these commands (one-time only):
tanzu project use PROJECT-NAME tanzu space use SPACE-NAME
-
In the same IDE terminal window, at the root of the workspace, build and deploy the application:
tanzu deploy
Applications being debugged must run at scale 1 so that the debugger has a single replica to connect to.
-
Verify that the application is running with debug enabled by inspecting the environment variables of the application:
tanzu apps get APP-NAME
If debug is enabled,
BPL_DEBUG_ENABLED
is set totrue
andBPL_DEBUG_PORT
is set to9005
.
Connect the debugger
To connect the debugger:
-
In the IntelliJ Project Explorer, find the
ContainerApp
YAML file for the application. -
Right-click the
ContainerApp
YAML file and click Tanzu > Debug. -
(Optional) If the Space does not have ingress configured, you can create additional port forwards to the application’s endpoints to provide access through a browser. For example,
http://localhost:8080
and other debugging tools.tanzu apps port-forward APP-NAME –port 8080:8080
-
To disconnect the debugger and end the debug session, click Stop in the Debug panel or on the toolbar. You can reconnect the session by following steps 1 and 2.
Content feedback and comments