Chapter 4. Example workflows for S2I on OpenShift 4.1. Remote debugging Java application for OpenShift image The example in the procedure shows the remote debugging of a Java application deployed on OpenShift by using the S2I for OpenShift image. You can enable the capability by setting the value of the environment variables JAVA_DEBUG to true and JAVA_DEBUG_PORT to 9009 , respectively. Note If the JAVA_DEBUG variable is set to true and no value is provided for the JAVA_DEBUG_PORT variable, JAVA_DEBUG_PORT is set to 5005 by default. Prepare for deployment Procedure Log in to the OpenShift instance by running following command and by providing your credentials: Create a new project: Deployment You can enable remote debugging for your new and existing applications. Enabling remote debugging for a new application Procedure Create a new application by using the S2I for OpenShift image and example Java source code. Ensure that you set the JAVA_DEBUG and the JAVA_DEBUG_PORT environment variables before creating your application: Proceed to Connect local debugging port to a port on the pod . Enabling remote debugging for an existing application Procedure Switch to the appropriate OpenShift project: Retrieve the name of the deploymentconfig : Edit the deploymentconfig and add the JAVA_DEBUG=true and JAVA_DEBUG_PORT=9009 environment variables. Specify object to edit at the path .spec.template.spec.containers and type of Container : Note Launch an editor to run oc edit command in your terminal. You can change the editor that is launched by defining your environment's EDITOR variable. Proceed to Connect local debugging port to a port on the pod . Post-deployment Connect local debugging port to a port on the pod Procedure Get the name of the pod running the application (Status Running ): Example showing openshift-quickstarts-1-1uymm as the pod name. Use the OpenShift or Kubernetes port forwarding feature to listen on a local port and forward to a port on the OpenShift pod. <running-pod> is the value of the NAME field for the pod with Status "running" from the command output: Note In the example, 5005 is the port number on the local system, while 9009 is the remote port number of the OpenShift pod running the S2I for OpenShift image. Therefore, future debugging connections made to local port 5005 are forwarded to port 9009 of the OpenShift pod, running the Java Virtual Machine (JVM). Important The command might prevent you from typing further in the terminal. In this case, launch a new terminal for performing the steps. Attach debugger to an application Procedure Attach the debugger on the local system to the remote JVM running on the S2I for OpenShift image: Note Once the local debugger to the remote OpenShift pod debugging connection is initiated, an entry similar to handling connection for 5005 is shown in the console where the oc port-forward command was issued. Debug the application: Additional resources For more information on Openshift common object reference, see the OpenShift Common Object Reference, section Container . For more information on connecting the IDE debugger of the Red Hat JBoss Developer Studio to the OpenShift pod running the S2I for OpenShift image, see Configuring and Connecting the IDE Debugger . 4.2. Running flat classpath JAR on source-to-image for OpenShift The example in the procedure describes the process of running flat classpath java applications on S2I for OpenShift. Prepare for Deployment Procedure Log in to the OpenShift instance by providing your credentials: Create a new project: Deployment Procedure Create a new application using the S2I for OpenShift image and Java source code: Post-deployment Procedure Get the service name: Expose the service as a route to be able to use it from the browser: Get the route: Access the application in your browser by using the URL (value of HOST/PORT field from command output).

Commands:
oc login
oc new-project js2i-remote-debug-demo
oc new-app --context-dir=getting-started --name=quarkus-quickstart 'registry.access.redhat.com/ubi8/openjdk-11~https://github.com/quarkusio/quarkus-quickstarts.git#2.12.1.Final' -e JAVA_DEBUG=true -e JAVA_DEBUG_PORT=9009
oc project js2i-remote-debug-demo
oc get dc -o name deploymentconfig/openshift-quickstarts
oc edit dc/openshift-quickstarts
oc get pods NAME READY STATUS RESTARTS AGE openshift-quickstarts-1-1uymm 1/1 Running 0 3m openshift-quickstarts-1-build 0/1 Completed 0 6m
oc port-forward <running-pod> 5005:9009 Forwarding from 127.0.0.1:5005 -> 9009 Forwarding from [::1]:5005 -> 9009
jdb -attach 5005 Set uncaught java.lang.Throwable Set deferred uncaught java.lang.Throwable Initializing jdb >
jdb -attach 5005 Set uncaught java.lang.Throwable Set deferred uncaught java.lang.Throwable Initializing jdb > threads Group system: (java.lang.ref.ReferenceUSDReferenceHandler)0x79e Reference Handler cond. waiting (java.lang.ref.FinalizerUSDFinalizerThread)0x79f Finalizer cond. waiting (java.lang.Thread)0x7a0 Signal Dispatcher running Group main: (java.util.TimerThread)0x7a2 server-timer cond. waiting (org.jolokia.jvmagent.CleanupThread)0x7a3 Jolokia Agent Cleanup Thread cond. waiting (org.xnio.nio.WorkerThread)0x7a4 XNIO-1 I/O-1 running (org.xnio.nio.WorkerThread)0x7a5 XNIO-1 I/O-2 running (org.xnio.nio.WorkerThread)0x7a6 XNIO-1 I/O-3 running (org.xnio.nio.WorkerThread)0x7a7 XNIO-1 Accept running (java.lang.Thread)0x7a8 DestroyJavaVM running Group jolokia: (java.lang.Thread)0x7aa Thread-3 running >
oc login
oc new-project js2i-flatclasspath-demo
oc new-app --context-dir=getting-started --name=quarkus-quickstart 'registry.access.redhat.com/ubi8/openjdk-11~https://github.com/quarkusio/quarkus-quickstarts.git#2.12.1.Final'
oc get svc
oc expose svc/openshift-quickstarts --port=8080
oc get route