cleancut-fluent

(Answer) (Category) iSeries / AS400 FAQ : (Category) Programming : (Category) Java :
Debugging Java programs running on the iSeries
If you are running V5R2 or higher, you can use any JPDA debugger you want.

Here are a few that I've found ...

There are probably plenty of others.
david

From the Green Screen:
From Paul

When you try to debug a Java class using the STRDBG command on the AS400, the command doesn't work unless the JVM is already running and your class is loaded.

I found that I was constantly getting the error 'Java class file not available.' I even tried the full pathname (eg. /home/myjava.class) but it didn't work even though I did have my environment CLASSPATH variable set properly. I pressed F1 to get a further explanation on the error and found out that the reason code returned was 1 for '1 - Java virtual machine not started.'.

Once my RPG program was loaded and had started the copy of my Java class, I was then able to debug the Java Code, since the JVM was now running. I also learned quickly that you have to match exactly, the name of the class in the STRDBG command matching upper and lower-case characters. As well, you don't enter in the extension of class. So my class name 'OraCon.class' was entered in as OraCon.

Another trick I used was to set a breakpoint in my RPG code to break at the point where the Java class was instantiated. Once the program hit this breakpoint, I then used F14 from within STRDBG and added the Java Class right after it was created. I was then able to use Option 5 'Display Module Source' and then set a break point in my Java code and then step through my Java class.


joepluta, david

When creating your Java program with the CRTJVAPGM, ensure that you keep your optimisation level low(10). If you set it too, high, you loose the debugging information and won't be able to properly step through your program. Using the java compiler option to include/exclude debugging information doesn't seem to affect the ability to debug your Java program using the interactive debugger. (STRDBG).
...Paul
pekrzyz
Here are some steps laid out by Barbara Morris in the iSeries newsgroup to debug an RPG program calling Java classes.

http://groups.google.ca/groups?selm=3D496F97.2848F26E%40ca.ibm.com&output=gplain

> I use STRDBG to debug an RPG program.  The RPG program is calling a
> Java method (via JNI V5R1.)  When I attempt to step into the Java
> method (F22) debugger does not proceed into the method but steps over
> it.
> 
> The JAR file containing the java class had been run through CRTJVAPGM
> with option 10.  The CLASS files were compiled with -g.
> 
> I'm guessing that the problem is that when I do a F22 it is trying to
> step into to JNI layer, not my class.  So if I could figure out how to
> bring up my class before doing the F22 I could set a breakpoint stop
> at it.  Am I on the right track? or totally off base.

Unfortunately, there are some debugging limitations when using
RPG and Java this way.  Debugging of Java code isn't supported when the
JVM is running in the same process as the debugger.  You will have to
debug from another job.

You also have to do CRTJVAPGM on the classes you want to debug.  If you
don't do this, your Java breakpoints won't work the way you expect. 
(You've already done this; I'm just putting this in for the record,
since it's an important step.)

You won't be able to step into the very first Java method.  You'll have
to wait until the JVM is started by RPG.  This doesn't happen until the
first Java method is called.  If you do want to debug the first method,
you'll have to wait until the time you run your program, or insert a
call into your RPG program to some dummy method just to get the JVM
started.

0. CRTJVAPGM 'yourclass.class' (you only need to do this once after you
create the class)

1. From the RPG job:
   a. ===> DSPJOB
   b. Get the Name, User and Number - you will need this in the next step (*)
2. From the debugging job:
   a. ===> STRSRVJOB JOB(Number/User/Name)
   b. ===> STRDBG yourRpgPgm
   c. ===> Exit with F10.
3. From the RPG job, call your program.
4. Go back to the debugging job to step through your program.
5. From the debugging job:
   a. ===> ENDDBG
   b. ===> ENDSRVJOB JOB(whatever)

(*) Another, maybe easier, way to get the job info is to do WRKJOB
OPTION(*SPLF) in the RPG job, and do a 2 on one of the spoolfiles.  Then
use cut-and-paste on all three job fields at once from the spoolfile to
the prompted STRSRVJOB command.
buck.calabro
ans-ins-part
Append to This Answer
Previous: (Answer) Why does my PC run Java so much faster than the iSeries?
Next: (Answer) Java and SQL stored procedure
This document is: http://faq.midrange.com/index.pl?file=299
[Search] [Appearance]
This is a Faq-O-Matic 2.721.