Unconfigured Ad Widget

Collapse

Announcement

Collapse
No announcement yet.

Debugging Java from RPG JNI

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Debugging Java from RPG JNI

    Try using Start Service Job (STRSRVJOB) command to service the job and then use STRDBG, similar to debuging a batch job. Why doesn't STRDBG work directly? I believe there is limitation with the setup you have outlined. If/when I find where that is documented then I'll post it. Tosh.

  • #2
    Debugging Java from RPG JNI

    Thanks Tosh, I just tried a simpler execution example and the program works! I think the error is somewhere in this complex SQL statement that I'm passing to the program. I'll try the STRSRVJOB and see what that does. Thanks a heap and Happy New Year! Best, Cliff PS. DOes anyone know how to get the STDOU stream from a Java program called through RPG JNI? I see some output flash very quickly to the screen when an error occurrs but I don't know how to trap that info.

    Comment


    • #3
      Debugging Java from RPG JNI

      Never tried with JNI, but when you're using QSH you just override STDOUT to a database file: CRTPF QTEMP/STDOUT RCDLEN(256) OVRDBF STDOUT STDOUT Maybe this will work for JNI, too? Joe

      Comment


      • #4
        Debugging Java from RPG JNI

        I just learned STRSRVJOB is not an option here because the Java does not run as a BCI boj. It runs within the RPG job natively hence the "N" in JNI. The issue here is kind of a mixed one because I'm trying to debug a program created with Eclipse (the open source version of the WSDc) that runs iSeries specific logic. In particular there is a JDBC snippet that I'm interested in analizing. It is using the native JDBC driver so I cannot run this piece of the code from my PC. I saw an option in eclipse for remote debugging but I'm not sure how to set my iSeries up so the remote debugger can attach to it. (I believe it connects through a port the default being 8000.) I looked on the IBM info center for documentation on remote JNI debugging and found nothing. They only include info regarding debugging command-line Java programs. I couldn't find an option in Eclipse to include debug info on the compile. This would have allowed me to do a command line debug just to sort things out. As you can see I having a hard time here. Help, Cliff

        Comment


        • #5
          Debugging Java from RPG JNI

          I tried the OVRDBF command earlier without thinking to create the STDOUT PF first. It didn't work but maybe because STDOUT wasn't created. I'll try your suggestion if I can ever get the bug to re-occur. Thanks a heap! Cliff

          Comment


          • #6
            Debugging Java from RPG JNI

            If you have the WebSphere Development Tools, then you have access to the IBM Distributed Debugger. It will step into Java code from RPG. I've done it, and I seem to remember there might be a trick to doing it (maybe .java file has to be present with the .class file?). Anyway, it works. Only caveat is that I wouldn't call it a speed demon, by any stretch of the imagination. --Robert

            Comment


            • #7
              Debugging Java from RPG JNI

              I'm not sure what you mean by WebSphere Development Tools. I have the... (looking in desk drawer...) wait a minute! I DO have the WebSphere Development Tools disks. Are you referring to the disks that ship w/ V5R1 upgrade? I was treating this as outdated technology and have been reluctant to install it. I don't know alot about VAJ and I've grown pretty comfortable w/ Eclipse. Truth is I didn't want to install all this stuff if I didn't have to. However, if what your saying is true I might just bite the bullet and install it anyway. I'm assuming that I'll have to debug the RPG from Code/400 right? Thanks a bunch everybody! Keep the replies comming, Cliff

              Comment


              • #8
                Debugging Java from RPG JNI

                I just installed WDSc 4.0 on my PC and downloaded Eclipse 2.0.2 but when I started the eclipse.exe I cant find the WDSC development tools and wont able to start WSDc. I cant even add to plug-ins. Is there an easy way to do this. Thanks a lot. Sky

                Comment


                • #9
                  Debugging Java from RPG JNI

                  Skywalker, I'm assuming you installed Eclipse 2.0.2 after WDSc. This is probably why you don't see the WDSc dev tools. WDSc already includes Eclipse and installing Eclipse overtop of a WDSc install is probably wiping out the WDSc stuff. Un-install everything and start over from the beginning. Just install WDSc and forget about downloading eclipse because it should already install with WDSc. Cliff PS. Could you burn and mail me a copy of your WDSc CDs?

                  Comment


                  • #10
                    Debugging Java from RPG JNI

                    5 CDs and a DVD. Should contain CODE/400, Toolbox for Java, VARPG, VAJ, and Webfacing tools along with the IBM Distributed Debugger. You don't have to use VAJ to use the debugger. If you've grown comfortable with Eclipse, stick with Eclipse (I think it's a better IDE anyway). --Robert

                    Comment


                    • #11
                      Debugging Java from RPG JNI

                      I just tried the override again and specified it at the job scope. I then ran my program seeing the error info flash before me. I checked the STDERR and STDOUT files I created in QTEMP and both were empty. Also it doesn't look like RPG is catching and reporting Java exceptions. Cliff

                      Comment


                      • #12
                        Debugging Java from RPG JNI

                        Robert, I'll try the WDT400 stuff. Thanks for the tip. Cliff

                        Comment


                        • #13
                          Debugging Java from RPG JNI

                          I'm using the new RPG JNI support and executing the Java app from RPG for optimization purposes. I suppose I could strip out the raw raw Java invocation code for debugging, I was just hoping I wouldn't have to do that. Cliff

                          Comment


                          • #14
                            Debugging Java from RPG JNI

                            Try this to override to database file: pgm dcl &java *char 256 chkobj obj(qtemp/stdout) objtype(*file) monmsg cpf9801 exec(do) crtpf qtemp/stdout rcdlen(96) enddo clrpfm qtemp/stdout ovrdbf file(stdout) tofile(qtemp/stdout) + mbr(stdout) ovrscope(*calllvl) chgvar &java ('java YourClass') qsh cmd(&JAVA) dltovr file(*ALL) lvl(*) endpgm And this to override to a print file: pgm dcl &java *char 256 ovrdbf file(stdout) tofile(qsysprt) + ovrscope(*calllvl) chgvar &java ('java YourClass') qsh cmd(&JAVA) dltovr file(*ALL) lvl(*) endpgm This works only when executing your java class via QSH not the JAVA CL command.

                            Comment


                            • #15
                              Debugging Java from RPG JNI

                              Creating a debug class like for example (very rough draft);
                              My disclaimer: This was done very quickly so I do not claim excellence in this example. It is just an example.
                               
                              Debug class
                              import java.util.Vector; public class Debug{ static Vector currentMsgs = new Vector(); static int currentIndex = -1; public static void debug(String msg) { currentMsgs.add(msg); } public static String getNextMessage() { if(currentIndex==currentMsgs.size()-1) currentIndex = -1; else currentIndex++; return (String)currentMsgs.get(currentIndex); } public static int getCount() { return currentMsgs.size(); } public static void clear() { currentMsgs.clear(); currentIndex = -1; } }
                              You could output statements like:
                              PrintJVM2 class
                               import java.io.*; class PrintJVM2{ static public void listJVM() { File[] f = File.listRoots(); Debug.debug("
                              Listing File System Roots..."); for(int i=0; i Listing File Separators..."); Debug.debug("File separator as String: " + File.separator); Debug.debug("File separator as Char: " + File.separatorChar); Debug.debug("Path separator as String: " + File.pathSeparator); Debug.debug("Path separator as Char: " + File.pathSeparatorChar); Debug.debug("
                              Listing JVM properties..."); Debug.debug("Java version: " + System.getProperty("java.version")); Debug.debug("Java vendor: " + System.getProperty("java.vendor")); Debug.debug("Java vendor URL: " + System.getProperty("java.vendor.url")); Debug.debug("Java installation directory: " + System.getProperty("java.home")); Debug.debug("Java Virtual Machine specification version: " + System.getProperty("java.vm.specification.version")); Debug.debug("Java Virtual Machine specification vendor: " + System.getProperty("java.vm.specification.vendor")); Debug.debug("Java Virtual Machine specification name: " + System.getProperty("java.vm.specification.name")); Debug.debug("Java Virtual Machine implementation version: " + System.getProperty("java.vm.version")); Debug.debug("Java Virtual Machine implementation vendor: " + System.getProperty("java.vm.name")); Debug.debug("Java Runtime Environment specification version: " + System.getProperty("java.specification.version")); Debug.debug("Java Runtime Environment specification name: " + System.getProperty("java.specification.vendor")); Debug.debug("Java class format version number: " + System.getProperty("java.class.version")); Debug.debug("Java class path: " + System.getProperty("java.class.path")); Debug.debug("List of paths to search when loading libraries: " + System.getProperty("java.library.path")); Debug.debug("Name of JIT compiler to use: " + System.getProperty("java.compiler")); Debug.debug("Path of extension directory or directories: " + System.getProperty("java.ext.dirs")); Debug.debug("Default temp file path: " + System.getProperty("java.io.tmpdir")); Debug.debug("Operating system name: " + System.getProperty("os.name")); Debug.debug("Operating system architecture: " + System.getProperty("os.arch")); Debug.debug("Operating system version: " + System.getProperty("os.version")); Debug.debug("File separator ("/" on UNIX): " + System.getProperty("file.separator")); Debug.debug("Path separator (":" on UNIX): " + System.getProperty("path.separator")); try{ Debug.debug("Line separator ("\n" on UNIX): " + Integer.decode(System.getProperty("line.separator"))); } catch(NumberFormatException nfe){}; Debug.debug("User's account name: " + System.getProperty("user.name")); Debug.debug("User's home directory: " + System.getProperty("user.home")); Debug.debug("User's current working directory: " + System.getProperty("user.dir")); } }

                              TestJNI pgm
                              And then report then in the RPG program like:
                               h Debug DftActGrp(*No) ActGrp(*new) Bnddir('QC2LE') d printf pr extproc('printf') d * value options(*string) d * value options(*string:*nopass) d * value options(*string:*nopass) d * value options(*string:*nopass) d listJVM pr extproc(*java d :'PrintJVM2' d :'listJVM') d static d getCount pr 10i 0 extproc(*java d :'Debug' d :'getCount') d static d getNextMessage... d pr o extproc(*java d :'Debug' d :'getNextMessage') d class(*java:'java.lang.String') d static d getBytes pr 256a extproc(*java d :'java.lang.String' d :'getBytes') varying d newline c x'25' d msg s o class(*java:'java.lang.String') d txt s 256a d max s 10i 0 d count s 10i 0 /free listJVM(); max = getCount(); for count = 1 to max; msg = getNextMessage(); txt = getBytes(msg); printf(newline+'%s':%trim(txt)); endfor; *inlr = *on; /end-free 
                              This is very rough but you could trigger the message retrieval by converting the java exception to an ILE exception - one possibility. You could also code the Debug class to output to System.out or to the Vector based on -D (setting a JVM property for Debug).

                              Comment

                              Working...
                              X