1

I've created an RPGLE program and I'm trying to execute a java .jar file from within. I've been able to get it to run from the QSH so I know it compiled and runs fine, but I need to run it from the program not QSH. Here is the code I have tried... CALLP(e) QcmdEXC(cmd_JAVAcall:%SIZE(cmd_JAVAcall));
and cmd_JAVAcall is set to

`RUNJVA CLASS('/home/MIGPCTOOD/MIGPCTOOD.jar') 
CLASSPATH('/home/MIGPCTOOD':'log4j.properties')   
PARM('/home/POSPDFMON' '/home/POSONDMON')`         

I also tried setting it to

'JAVA CLASS('/home/MIGPCTOOD/MIGPCTOOD.jar')     
CLASSPATH('/home/MIGPCTOOD':'log4j.properties')   
PARM('/home/POSPDFMON' '/home/POSONDMON')'

     

Neither one seems to actually launch the program but it doesnt produce and error either.

Any thoughts on how I can launch this java?

wendy
  • 21
  • 1
  • 2
    Not knowing anything about RPGLE, I'd guess that the `CLASS()` wants the class name, not the .jar file, and `CLASSPATH(...)` should list the jars and other resources. – Jim Garrison Mar 02 '22 at 19:47

1 Answers1

1

Calling Java from RPG generally means calling individual Java methods... like so:

Java HelloWorld

class HelloWorld
{
    public static void Hello ()
    {
        System.out.println("Hello World") ;
    }
}

RPGLE program..

H DFTACTGRP(*NO)                                      
D sayhello        PR                  EXTPROC(*JAVA   
D                                     :'HelloWorld'   
D                                     :'Hello')       
D                                     Static          
C                   callp     sayhello                
C                   eval      *INLR = *ON 

You are not "calling Java from RPG" you are just calling the IBM i command interpreter (QCMDEXE). The fact you are asking the OS to run Java is immaterial.

You don't show your actual code, but I suspect you're running into an issue with embedded quotes in your command string...

You'd normally have to double the quotes to embed them. It's usually easier to define a constant value and make use of that.

try the following:

dcl-c QT const('''');
dcl-s cmd char(1024);

 cmd = 'RUNJVA CLASS(' 
       + QT +'/home/MIGPCTOOD/MIGPCTOOD.jar' + QT  
       + ') CLASSPATH(' 
       + QT + '/home/MIGPCTOOD:log4j.properties' + QT 
       + ') PARM(' 
       + QT + '/home/POSPDFMON' + QT 
       + ' '
       + QT +'/home/POSONDMON' + QT 
       + ')';

I can't promise I've got it exactly right, but you'll get the general idea.

If you run the program in debug, you'll be able to validate that the embedded quotes are showing properly.

Charles
  • 21,637
  • 1
  • 20
  • 44
  • Thank you so much for you help. I put the code in debug and this is what is being executed with the QcmdExec RUNJVA CLASS('/home/MIGPCTOOD/MIGPCTOOD.jar') CLASSPATH('/home/MIGPCTOOD':'log4j.properties') PARM('/home/POSPDFMON' '/home/POSONDMON') Does this look correct with the apostrophe's? – wendy Mar 03 '22 at 13:59
  • 1
    @wendy Since you are running it through QCMDEXEC then it is the same as running on the command line so take your RUNJVA.... and try running on the command line and see if it works. – Scott Mildenberger Mar 03 '22 at 14:49
  • I think classpath should be `CLASSPATH('/home/MIGPCTOOD:log4j.properties')` take out the middle set of quotes. Answer has been edited – Charles Mar 03 '22 at 15:19