Cannot call .Jar file from RPGLE

Viewed 70

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?

1 Answers

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.

Related