ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

RPG/Java main method question

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • RPG/Java main method question

    Hello,

    I am trying to use a java program with a main method inside my RPG. I havent ever tried to use RPG with a main method before. Im kinda confused about main methods and constructors in RPG

    The main method accepts 2 parms, Im getting a signature problem when trying to call the main method. Im passing in the 2 parms as java string but it's not buying it ...The program works when I call it from qsh passing the two parms...(yea...). My classpath seems to be correct, it's finding it from qsh.

    I think Im going to have to remove the main method and call the individual methods. I was trying to avoid that if possible.

    Code:
    D CryptString     S               O   CLASS(*JAVA              
    D                                         : 'CryptString')     
                                                                          
    D new_CryptString...                                                  
    D                 PR                  like(CryptString)               
    D                                     EXTPROC(*JAVA                   
    D                                     :'CryptString'                  
    D                                     :*CONSTRUCTOR)                  
    D xString                             like(jString)                   
    D yString                             like(jString)                   
    D
    Code:
     aString = new_String('password');                   
     bString = new_String('supersecretpassword');                   
     CryptString = new_CryptString(aString:bString);   //Getting main not found

  • #2
    Re: RPG/Java main method question

    Never mind. I found it.

    I had to set up the RPG to use a static main method.


    Code:
    D CryptString...                                                        
    D                 PR                  STATIC                            
    D                                     EXTPROC(*JAVA                     
    D                                     :'CryptString'                    
    D                                     :'main')                          
    D                                 O   CLASS(*JAVA:'java.lang.String')   
    D                                     DIM(2) CONST                      
    D                                                                       
    D args            S               O   CLASS(*JAVA:'java.lang.String')   
    D                                     DIM(2)                            
    
     args(1)  = new_String('password');    
     args(2)  = new_String('supersecretpassword');    
     CryptString(args);
    I hope this helps someone ...

    Comment


    • #3
      Re: RPG/Java main method question

      By the way, if the number of parameters isn't fixed, you can code the RPG prototype and the array with the maximum DIM needed by the method, and then code %SUBARR(args : 1 : num_args) on the call.

      Also by the way, you can't pass zero parameters to a Java main method, because Java requires that the method be defined with an array of String. So the RPG prototype has to have an array parameter, but there's no way, even with %SUBARR, for an RPG program to pass an array with zero elements.

      Comment


      • #4
        Re: RPG/Java main method question

        Thank You,

        You replied to one of my earlier threads about java casting.

        Do you have an example of what you were saying about that.

        Setting up a DS with offsets and so forth. It would be MOST appreciated.

        Thank You for your reply.

        Comment

        Working...
        X