|
This is a multipart message in MIME format. -- [ Picked text/plain from multipart/alternative ] I have couple of questions: 1) I am trying to start JVM with properties through using JNI api JNI_CreateJavaVM. Thanks to the help from Barbara Morris, I put together the pgm-1 below, and it works OK to create JVM with a single property. But when I try to pass multiple properties in pgm-2, it doesn't work. Could anybody see what is it I am doing wrong in pgm-2 ? (Launcher class has a simple method PrtSysPrt to print system properties to test whether JVM creation went OK.) 2) Barbara also recommended me to define JNI_CreateJavaVM parameters in a C pgm then import it to RPG. It works greately even for multiple properties. I was able to write a simple C pgm and hard code my properties. Pgm-3 is the RPG that imports the JNI parm from the C pgm-4. But my properties are not static, so If I can improve pgm-4 to get property values as paramaters, and build the options array, then return the optadr variable, I can call pgm-4 from pgm-3, pass the properties, then it should do what I want. Could anybody help me to make pgm-4 improvements in C language? (I did try to write pgm-5, but I can not compile it.) Thanks for all the help in advance. Ali ===================================================================== Program-1. ===================================================================== /define OS400_JVM_12 h thread(*serialize) h dftactgrp(*no) * * This pgm builds a single option, and * starts JVM with that property. * * * Include JNI declarations and prototypes * /copy qsysinc/qrpglesrc,jni * * Declare HostManager class, methods, and params * d PrtSysPrt PR EXTPROC(*JAVA: d 'Launcher': d 'PrtSysPrp') d STATIC * * Delcare local procedure pointers * d getJniEnv PR * ************************************************************************** * Mainline ************************************************************************** /free JNIEnv_P=getJniEnv(); PrtSysPrt(); *inlr = *on; return; /end-free ************************************************************************** * Procedure - getJniEnv ************************************************************************** p getJniEnv B EXPORT d getJniEnv PI * d rc S LIKE(jint) d rpgRc S N d jvm S * DIM(1) d env S * d bufLen S LIKE(jsize) INZ(%elem(jvm)) d nVMs S LIKE(jsize) * Declare input structures for creating/attaching the JVM d initArgs2 DS LIKEDS(JavaVMInitArgs) d attachArgs2 DS LIKEDS(JavaVMAttachArgs) d singleOption DS LIKEDS(JavaVMOption) d qdcxlate PR EXTPGM('QDCXLATE') d xLen 5P 0 CONST d xData 1000A OPTIONS(*VARSIZE) d xTable 10A d temp S 1000A d lenParam S 5P 0 STATIC d dataParam S * STATIC d tableParam S 10A INZ('QASCII ') STATIC d optStrXX S 256A VARYING d INZ('-Dtest=SingleInternalOption') /free //--------------------------------------------------------------------- // See if there's a JVM started //--------------------------------------------------------------------- rc = JNI_GetCreatedJavaVMs (jvm : bufLen : nVMs); //--------------------------------------------------------------------- // If JVM is started, just attach to it, to get the env pointer //--------------------------------------------------------------------- if (rc = 0 and nVMs > 0); // #gwo -- PRE-EXISTING VM IS NOT ALLOWED // WE NEED TO THROW AN EXCEPTION attachArgs2 = *ALLX'00'; attachArgs2.version = JNI_VERSION_1_2; JavaVM_P = jvm(1); rc = AttachCurrentThread (jvm(1): env : %addr(attachArgs2)); //--------------------------------------------------------------------- // If JVM is not started, start it //--------------------------------------------------------------------- else; // Set VM arguments temp = optstrXX; callp qdcxlate(%len(optstrXX) : temp : tableParam); optstrXX = %subst(temp : 1 : %len(optstrXX)) + x'00'; optStrXX= optStrXX+x'00'; singleOption.optionString = %addr(optStrXX)+2; singleOption.extraInfo = *NULL; initArgs2.version = JNI_VERSION_1_2; initArgs2.nOptions = 1; initArgs2.options = %addr(singleOption); rc = JNI_CreateJavaVM (jvm(1) : env : %addr(initArgs2)); // Display result dsply rc; endif; if (rc = 0); return env; else; return *NULL; endif; /end-free P getJniEnv E ===================================================================== ===================================================================== Program-2. ===================================================================== /define OS400_JVM_12 h thread(*serialize) h dftactgrp(*no) * * This pgm builds multiple JVM options, and * starts JVM with that properties. * * * Include JNI declarations and prototypes * /copy qsysinc/qrpglesrc,jni * * Declare HostManager class, methods, and params * d PrtSysPrt PR EXTPROC(*JAVA: d 'Launcher': d 'PrtSysPrp') d STATIC * * Delcare local procedure pointers * d getJniEnv PR * ************************************************************************** * Mainline ************************************************************************** /free JNIEnv_P=getJniEnv(); PrtSysPrt(); *inlr = *on; return; /end-free ************************************************************************** * Procedure - getJniEnv ************************************************************************** p getJniEnv B EXPORT d getJniEnv PI * d rc S LIKE(jint) d rpgRc S N d jvm S * DIM(1) d env S * d bufLen S LIKE(jsize) INZ(%elem(jvm)) d nVMs S LIKE(jsize) * Declare input structures for creating/attaching the JVM d initArgs2 DS LIKEDS(JavaVMInitArgs) d attachArgs2 DS LIKEDS(JavaVMAttachArgs) d vmOptions DS LIKEDS(JavaVMOption) d OCCURS(7) d qdcxlate PR EXTPGM('QDCXLATE') d xLen 5P 0 CONST d xData 1000A OPTIONS(*VARSIZE) d xTable 10A d temp S 1000A d lenParam S 5P 0 STATIC d dataParam S * STATIC d tableParam S 10A INZ('QASCII ') STATIC d optStr01 S 256A VARYING d INZ('-Dtest=MultInternalOpt') d optStr02 S 256A VARYING d INZ('-Dali=ali222222222') d optStr03 S 256A VARYING d INZ('-Djava.ext.dirs=+ d /ALIEKINCI/test') d optStr04 S 256A VARYING d INZ('-Djava.naming.factory.initial=+ d com.pjx.naming.context.PjxInitial+ d ContextFactory') d optStr05 S 256A VARYING d INZ('-Djava.naming.factory.url.+ d pkgs=com.pjx.naming') d optStr06 S 256A VARYING d INZ('-Djava.naming.provider.url=+ d rmi://localhost:34999') d optStr07 S 256A VARYING d INZ('-Dcom.pjx.scs.HostName=+ d USATLD06') /free //--------------------------------------------------------------------- // See if there's a JVM started //--------------------------------------------------------------------- rc = JNI_GetCreatedJavaVMs (jvm : bufLen : nVMs); //--------------------------------------------------------------------- // If JVM is started, just attach to it, to get the env pointer //--------------------------------------------------------------------- if (rc = 0 and nVMs > 0); // #gwo -- PRE-EXISTING VM IS NOT ALLOWED // WE NEED TO THROW AN EXCEPTION attachArgs2 = *ALLX'00'; attachArgs2.version = JNI_VERSION_1_2; JavaVM_P = jvm(1); rc = AttachCurrentThread (jvm(1): env : %addr(attachArgs2)); //--------------------------------------------------------------------- // If JVM is not started, start it //--------------------------------------------------------------------- else; // Set VM options %occur(vmOptions) = 1; temp = optstr01; callp qdcxlate(%len(optstr01) : temp : tableParam); optstr01 = %subst(temp : 1 : %len(optstr01)) + x'00'; vmOptions.optionString = %addr(optStr01)+2; vmOptions.extraInfo = *NULL; %occur(vmOptions) = 2; temp = optstr02; callp qdcxlate(%len(optstr02) : temp : tableParam); optstr02 = %subst(temp : 1 : %len(optstr02)) + x'00'; vmOptions.optionString = %addr(optStr02)+2; vmOptions.extraInfo = *NULL; %occur(vmOptions) = 3; temp = optstr03; callp qdcxlate(%len(optstr03) : temp : tableParam); optstr03 = %subst(temp : 1 : %len(optstr03)) + x'00'; vmOptions.optionString = %addr(optStr03)+2; vmOptions.extraInfo = *NULL; %occur(vmOptions) = 4; temp = optstr04; callp qdcxlate(%len(optstr04) : temp : tableParam); optstr04 = %subst(temp : 1 : %len(optstr04)) + x'00'; vmOptions.optionString = %addr(optStr04)+2; vmOptions.extraInfo = *NULL; %occur(vmOptions) = 5; temp = optstr05; callp qdcxlate(%len(optstr05) : temp : tableParam); optstr05 = %subst(temp : 1 : %len(optstr05)) + x'00'; vmOptions.optionString = %addr(optStr05)+2; vmOptions.extraInfo = *NULL; %occur(vmOptions) = 6; temp = optstr06; callp qdcxlate(%len(optstr06) : temp : tableParam); optstr06 = %subst(temp : 1 : %len(optstr06)) + x'00'; vmOptions.optionString = %addr(optStr06)+2; vmOptions.extraInfo = *NULL; %occur(vmOptions) = 7; temp = optstr07; callp qdcxlate(%len(optstr07) : temp : tableParam); optstr07 = %subst(temp : 1 : %len(optstr07)) + x'00'; vmOptions.optionString = %addr(optStr07)+2; vmOptions.extraInfo = *NULL; // Set VM arguments %occur(vmOptions) = 1; initArgs2.version = JNI_VERSION_1_2; initArgs2.nOptions = 7; initArgs2.options = %addr(vmOptions); rc = JNI_CreateJavaVM (jvm(1) : env : %addr(initArgs2)); // Display result dsply rc; endif; if (rc = 0); return env; else; return *NULL; endif; /end-free P getJniEnv E ===================================================================== Program-3. ===================================================================== /define OS400_JVM_12 h thread(*serialize) * * This pgm imports the JVM properties structure from C module pgm-4 * * * Include JNI declarations and prototypes * /copy qsysinc/qrpglesrc,jni * * Declare HostManager class, methods, and params * d PrtSysPrt PR EXTPROC(*JAVA: d 'Launcher': d 'PrtSysPrp') d STATIC d optadr S * import('optadr') * * Delcare local procedure pointers * d getJniEnv PR * ************************************************************************** * Mainline ************************************************************************** /free JNIEnv_P=getJniEnv(); PrtSysPrt(); *inlr = *on; return; /end-free ************************************************************************** * Procedure - getJniEnv ************************************************************************** p getJniEnv B EXPORT d getJniEnv PI * d rc S LIKE(jint) d rpgRc S N d jvm S * DIM(1) d env S * d bufLen S LIKE(jsize) INZ(%elem(jvm)) d nVMs S LIKE(jsize) * Declare input structures for creating/attaching the JVM d attachArgs2 DS LIKEDS(JavaVMAttachArgs) d qdcxlate PR EXTPGM('QDCXLATE') d xLen 5P 0 CONST d xData 1000A OPTIONS(*VARSIZE) d xTable 10A d temp S 1000A d lenParam S 5P 0 STATIC d dataParam S * STATIC d tableParam S 10A INZ('QASCII ') STATIC /free //--------------------------------------------------------------------- // See if there's a JVM started //--------------------------------------------------------------------- rc = JNI_GetCreatedJavaVMs (jvm : bufLen : nVMs); //--------------------------------------------------------------------- // If JVM is started, just attach to it, to get the env pointer //--------------------------------------------------------------------- if (rc = 0 and nVMs > 0); // #gwo -- PRE-EXISTING VM IS NOT ALLOWED // WE NEED TO THROW AN EXCEPTION attachArgs2 = *ALLX'00'; attachArgs2.version = JNI_VERSION_1_2; JavaVM_P = jvm(1); rc = AttachCurrentThread (jvm(1): env : %addr(attachArgs2)); //--------------------------------------------------------------------- // If JVM is not started, start it //--------------------------------------------------------------------- else; // Set VM arguments rc = JNI_CreateJavaVM (jvm(1) : env : optadr); dsply rc; endif; if (rc = 0); return env; else; return *NULL; endif; /end-free P getJniEnv E ===================================================================== Program-4. ===================================================================== #define OS400_JVM_12 #include <jni.h> /* Specify the pragma that causes all literal strings in the * source code to be stored in ASCII (which, for the strings * used, is equivalent to UTF-8) */ #pragma convert(819) char *option1 = "-Dtest=SingleCimportedoOptionnnnnnnnnnnnnnnnnn"; JavaVMOption options[4] = { { "-Dxxx=yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy", 0 }, { "-Dx=y", 0 }, { "-Dzzzzzzzzzzzzz=aliiiiiiiiiiiiiiiiiiiiiiiiii",0 }, { "-Djava.naming.provider.url=rmi://localhost:34999", 0 } }; JavaVMInitArgs initArgs = { 0x00010002,4,options,1 }; JavaVMInitArgs *optadr = &initArgs; ===================================================================== Program-5. ===================================================================== #define OS400_JVM_12 #include <jni.h> #pragma convert(819) void main(int argc, char *argv[]) { JavaVMOption options[10]; JavaVMInitArgs initArgs; JavaVMInitArgs *optadr; int i; for (i=0; i<argc; ++i); options[i].optionString=argv[i]; initArgs.version = 0x00010002; initArgs.nOptions = argc-1; initArgs.options = options; initArgs.ignoreUnrecognized = 1; JavaVMInitArgs *optadr = &initArgs; }
As an Amazon Associate we earn from qualifying purchases.
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.