I finally figured this one out.  As you know, the main method of a Java
class is a special method.  It is always defined as "public static void"
with an argument of a string array.  This provides some special
circumstances for calling this method from within an RPG program.  After
referencing the RPG Programmers manual and some trial and error, I have come
up with the resolution.  Why the importance of the main method you ask?
Well, when I develop classes, and other Java programmers I have spoken to, I
code the main method to test all aspects of the class.  Normally I print the
results out to System.out.  Well, enough babble.  Lets look at the example
and the explanation.

Calling the main method -- and the appropriate definitions

first, define the parameter array:

D  args           S               O    Class(*JAVA:'java.lang.String')
D                                           DIM(1)

Next, define the main method prototype:

D main            PR                  ExtProc(*JAVA:
D                                          'com.shipley.ssl.CRD001J':
D                                          'main')
D                                          STATIC
D                                    O   Class(*JAVA:'java.lang.String')
D                                         CONST
D                                         DIM(1)
D                                         OPTIONS(*VARSIZE)


Note on the prototype - the array definition must be the same size as the
definition of the "args" variable.  Remember, this is a static method, so it
must be prototyped as such.

Next, define the prototype to create a String object:

D string          PR              O   ExtProc(*JAVA:
D                                               'java.lang.String':
D                                               *CONSTRUCTOR)
D   value                      100A   CONST VARYING

Finally, add an element to the array & call the method:

/Free
    args(1) = string('Test Value');
    main(args);
/End-Free

Remember that RPG arrays are based on 1 where Java arrays are zero based.
The main method in the class I am testing does not require any parameters.
Actually, the class will not reference any parameters passed in to the
method.  You MUST pass a valid array to the method on the call.  I tried
passing *NULL without any luck.  I tried to pass an empty array with no
luck.

Hope this helps someone out there!

Mike





As an Amazon Associate we earn from qualifying purchases.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.