Troubleshooting
Problem
This document provides an example of a CL program that calls
QSHELL
and then runs a Java™ Class.Resolving The Problem
Caution: As is only. IBM accepts no responsibility for its correctness. |
This sample is intended to demonstrate a couple of points.
1) How to direct the
stdout
messages to an output file2) How to construct the
classpath
and invoke qshell
to call the Java™ class.3) Sometimes it is necessary to pass arguments to a Java™ class.
This sample illustrates how to pass 2 arguments.
For completeness here is the Java™ class.
This class simply echos back the arguments passed into the class.
The following is an example of a CL program that calls
This class simply echos back the arguments passed into the class.
public class HP {
public static void main(String args[]) {
for (int i = 0; i < args.length; i++)
System.out.println("Hello " + args[i]);
}
}
The following is an example of a CL program that calls
QSHELL
and then runs a Java™ Class.PGM
DCL VAR(&MYCLASS) TYPE(*CHAR) LEN(30) VALUE('HP')
DCL VAR(&JAVA) TYPE(*CHAR) LEN(512)
DCL VAR(&PARM) TYPE(*CHAR) LEN(512)
DCL VAR(&CLASSPATH) TYPE(*CHAR) LEN(512) VALUE('-cp +
/home/tosh/toshifs520/')
DCL VAR(&MYPARM1) TYPE(*CHAR) LEN(10) +
VALUE('Winner')
DCL VAR(&MYPARM2) TYPE(*CHAR) LEN(20) VALUE('Hotdog')
DLTF FILE(XZY2435/JAVATST)
MONMSG MSGID(CPF2105)
CRTPF FILE(XZY2435/JAVATST) RCDLEN(132) +
TEXT('JAVA RUN') MAXMBRS(*NOMAX)
OVRDBF FILE(STDOUT) TOFILE(XZY2435/JAVATST)
CHGVAR VAR(&PARM) VALUE(&PARM *bcat &MYPARM1)
CHGVAR VAR(&PARM) VALUE(&PARM *bcat &MYPARM2)
CHGVAR VAR(&JAVA) VALUE('java ' *BCAT &CLASSPATH *BCAT +
&MYCLASS *BCAT &PARM)
QSH CMD(&JAVA)
ENDPGM
The Java™
stdout
messages are placed in the output file:DSPPFM XZY2435/JAVATST
Hello Winner
Hello Hotdog
[{"Type":"MASTER","Line of Business":{"code":"LOB68","label":"Power HW"},"Business Unit":{"code":"BU070","label":"IBM Infrastructure"},"Product":{"code":"SWG60","label":"IBM i"},"ARM Category":[{"code":"a8m3p0000006x8GAAQ","label":"CL"}],"ARM Case Number":"","Platform":[{"code":"PF012","label":"IBM i"}],"Version":"All Versions"}]
Historical Number
N1015682
368880934
Was this topic helpful?
Document Information
More support for:
IBM i
Component:
CL
Software version:
All Versions
Operating system(s):
IBM i
Document number:
638515
Modified date:
06 December 2024
UID
nas8N1015682
Manage My Notification Subscriptions