Remote Debug of Java using RDi

From MidrangeWiki
Revision as of 09:10, 23 August 2016 by Jmarkmurphy (talk | contribs) (Created page with "Debugging using SEP's in RDi is a huge productivity booster for developers, but it only supports ILE languages. Notably missing from that is Java. While RPG can call Java meth...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Debugging using SEP's in RDi is a huge productivity booster for developers, but it only supports ILE languages. Notably missing from that is Java. While RPG can call Java methods, the ILE debugger is unable to follow the program flow into the Java code. This page discusses just how to make that happen using RDi and the remote Java debug capability built into Eclipse. This appeared in Eclipse 3.4 (Ganymede), so should be available at least back to RDi 8.0? I am working in RDi 9.5, so these instructions are specific to that release. I found a blog on developerworks that helped immensely [1].


  1. Start a remote debug session in Eclipse
  2. Start up your JVM in remote debug mode
  3. Set up you SEP
  4. Call the RPG program you wish to debug


There is some initial setup required for this to work. You need to have a remote debug session configured in Eclipse, and a way to start your JVM in remote debug mode on IBM i. Here is what I did:

Eclipse - Create a Remote Debug Configuration

Open your RDi workspace and make sure you are in the RSE perspective (the menus are shorter)

1. Navigate the menu to Run->Debug Configurations...

2. Select Remote Java Application, and create a new configuration there


3. In the right hand side of the dialog, name your remote debug session, and tell it which project contains the jars you will be debugging. I have some extension that I have developed to help with calling into Apache POI, and that project has in it's classpath everything I need to debug, so that is the Project I selected.

4. Select a Connection Type. This should be Standard (Socket Listen).

5. And make sure Allow termination of remote VM is not checked. This is a deviation from the Developerworks blog, but I don't want to be terminating the JVM on IBM i. That would require me to log off then back on to IBM i for each debug session. You only get one JVM per job on IBM i, and once it is terminated, the only way to get a new one is to start a new job (log back in).


6. Click Apply, then Close

IBM i - CL Program

The easiest way to make sure you have a reliably started JVM is to create a CL program to do it. I have two, one for debugging, and one for non debugging. The only difference is the -Xdebug and -Xrunjdwp options. Here is my debug CL

            DCLPRCOPT  DFTACTGRP(*NO) ACTGRP(*NEW) BNDDIR(JCS) +                         
            DCL        VAR(&POINTER) TYPE(*PTR)                                          
              ADDENVVAR  ENVVAR(CLASSPATH) +                                             
                           ') LEVEL(*JOB) REPLACE(*YES)                                  
            ADDENVVAR  ENVVAR(QIBM_RPG_JAVA_PROPERTIES) +                                
                         ') REPLACE(*YES)                                                
            ADDENVVAR  ENVVAR(QIBM_USE_DESCRIPTOR_STDIO) VALUE('Y')                      
            ADDENVVAR  ENVVAR(JAVA_HOME) +                                               
                         ) REPLACE(*YES)                                                 
            ADDENVVAR  ENVVAR(QIBM_RPG_JAVA_EXCP_TRACE) VALUE('Y')                       
            CALLPRC    PRC(START_JVM) RTNVAL(&POINTER)                                   
OUT:        ENDPGM 

Look in environment variable QIBM_RPG_JAVA_PROPERTIES, the properties -Xdebug;-Xrunjdwp:transport=dt_socket,address=,suspend=y; is the secret sauce to have your JVM connect to the debugger in RDi. You must of course change the IP in address to the IP address of your PC so that the JVM can find it.

One note here, the procedure START_JVM is a procedure from Scott Klement's HSSF service program which you can get from his website [2]. You have to make a modification to export the procedure, but otherwise it is in there.


Now you are ready to go:

  1. Go back and select the remote debug configuration you created earlier and click Debug. You should see a Waiting for connection message to appear in the bottom right hand corner of your RDi window.
  2. Call your JVM Startup CLP from your green screen command line. You should see the Waiting for connection message go away.
  3. Now go set up your SEP and call the RPG you wish to debug. You can step directly into the Java methods from your RPG code.


In the RDi Debug View, you will see both the IBM J9 VM and the IBM i: Incoming Remote Debug Session. The RPG procedures and stack will be visible in the IBM i: Incoming Remote Debug Session. The Java stack with be in the J9 section. You can click on any procedure to go straight to the source. Debug as you would with SEP's


[1]Debug Java applications remotely with Eclipse