|
There should be a stack trace somewhere showing exactly what's causing the exception, probably a FileNotFound or an authority problem. If you can't locate the stack trace in the job log or spool files, place a try/catch block around the offending statement and in the catch block to a printStackTrace. HTH, Gary > -----Original Message----- > From: java400-l-bounces@xxxxxxxxxxxx > [mailto:java400-l-bounces@xxxxxxxxxxxx] On Behalf Of > David_Hinselwood@xxxxxxxxxxxxxxxxx > Sent: Thursday, October 30, 2003 6:49 AM > To: java400-l@xxxxxxxxxxxx > Subject: Problem calling custom java methods from RPG in a SBMJOB > > > Help! > > I had no luck posting this on the RPG400 mailing list, so here goes: > > I've been tinkering (fumbling blindly would be more accurate) > around with > calling Java methods from > RPG to generate / update Excel spreadsheets (using the > classes provided by > the Jakarta Poi APIs - > http://jakarta.apache.org/poi/hssf/index.html). I did a > search of the news > group and it seems some > people have been using this stuff with a greater degree of > success than > me, but couldn't find > anything that would solve my problem directly. > > I've managed to write a couple of proof-of-concept programs > (hence the > shoddy code below) that will > run in batch and interactive mode to create spreadsheets from > scratch and > write them out to the > IFS (which are then emailed out to users). > Creating xls from scratch seems to work just fine. > I'm having a problem when I try to open up an existing > spreadsheet for > updating inside a batch job > ( I only need to change the contents of particular cells & > re-save the > file). > > I can call my program interactively with no problems at all > and get an > updated spreadsheet at the end > of it that is persisted to the IFS, but if I try to run it is > a batch job > with a SBMJOB I get the error > message: > > ***** > Message . . . . : Java exception received when calling Java > method. > Cause . . . . . : RPG procedure JAVAXLS8 in program > DHWORKLIB/JAVAXLS8 > received Java exception "java.io.IOException:" when calling method > "<init>" > with signature "(Ljava.io.InputStream;)V" in class > "org.apache.poi.poifs.filesystem.POIFSFileSystem". Recovery > . . . : > Contact the person responsible for program maintenance to > determine the > cause of the problem. Technical description . . . . . . . . > : If the > exception indicates that the Java class was not found, > ensure the class > for > the method is in the class path. If the exception indicates > that the Java > > method was not found, check the method name and signature. If the > signature > is not correct, change the RPG prototype for the method, or > change the > Java > method, so that the return type and parameter types match. You can > determine > the signatures for all the methods in class XYZ using command QSH > CMD('javap > -s XYZ'). > ***** > > Not much help to the uninitiated .... > > Here's some code snippets / prototypes from the program in question: > > > 0008.00 D jInStream S O CLASS(*JAVA: > > 0009.00 D > 'java.io.InputStream') > 0020.00 * // openHandle = openFile( fileName) > > 0021.00 D openFile PR O EXTPROC(*JAVA: > > 0022.00 D > 'java.io.FileInputStream': > 0023.00 D *CONSTRUCTOR) > > 0024.00 D fileName O CLASS(*JAVA: > > 0025.00 D > 'java.lang.String') > > > > 0021.00 * // createPOIFSFileSystemForInput( > java.io.InputStrean) > 0022.00 * // Creates a POI FileSystem object from a java > input stream, > 0023.00 * // required for reading exising xls files. > 0024.00 D createPOIFSFileSystemForInput... > 0025.00 D PR O EXTPROC(*JAVA: > 0026.00 D 'org.apache.poi.poifs.filesystem- > 0027.00 D .POIFSFileSystem': > 0028.00 D *CONSTRUCTOR) > 0032.00 D inputStream O CLASS(*JAVA: > 0033.00 D > 'java.io.InputStream') > > > ---> > Main code begins here: > > 0015.00 D Recursive S N > 0016.00 D JNIEnv_P S * > 0017.00 D capacity S 10I 0 INZ(10000) > > 0018.00 D rowPos S 5 0 > 0019.00 D rowPosSave S 5 0 > 0020.00 D cellPos S 5 0 > 0021.00 D IFSFile S 1024 VARYING > 0022.00 D > INZ('/tmp/tstSales.xls') > 0023.00 D wrkChar S 1024 VARYING > 0024.00 D wrkDouble S LIKE( jDouble) > > ... > 0032.00 > *------------------------------------------------------------- > -------* > 0033.00 * Object variables * > 0034.00 > *------------------------------------------------------------- > -------* > 0035.00 D wrkString S LIKE( jString) > 0036.00 D trimmedString S LIKE( jString) > 0037.00 D filename S LIKE( jString) > 0038.00 D inFile S LIKE( jInStream) > 0039.00 D outFile S LIKE( jOutStream) > 0040.00 D fs S LIKE( > poiFileSystem) > 0041.00 D wb S LIKE( poiWorkbook) > 0042.00 D sheet1 S LIKE( poiSheet) > 0043.00 D row S LIKE( poiRow) > ... > 0104.00 Monitor; > > 0105.00 > > 0106.00 // Set the classpath > > 0107.00 cmdString = 'ADDENVVAR ENVVAR(CLASSPATH) VALUE(' + > x'7D' + > 0108.00 cCLASSPATH + x'7D' + ') > REPLACE(*YES)'; > 0109.00 RunCmd( %TRIMR( cmdString) ); > > 0110.00 > > 0111.00 > > 0112.00 // Get pointer to JNI Environment > > 0113.00 JNIEnv_P = getJNIEnv('-Djava.version=1.3;'); > > 0114.00 If JNIEnv_P = *NULL; > > 0115.00 *INLR = *ON; > > 0118.00 > 0119.00 // Create a new local reference frame so we can > clear all the > > 0120.00 // java objects in one go > 0121.00 > 0122.00 beginObjGroup( JNIEnv_P: capacity); > 0123.00 > 0124.00 // Open the file > 0125.00 wrkString = createString( %trim(IFSFile)); > 0126.00 // Trim filename (50A). > 0127.00 filename = trimString( wrkString); > 0128.00 // Create FileInputStream. > 0129.00 inFile = openFile( filename); > 0130.00 fsBytes = fsBytesAvail( inFile); > 0131.00 // Load the file into the POI filesystem > 0132.00 fs = createPOIFSFileSystemForInput( inFile); > > > The error here at statement 0132.00. A batch job doesn't seem > to have any > problems coping with > calling other Java methods, including those within the > poi.jar (though I > haven't tested exhaustively > to find any others that don't work). I've tried setting the CLASSPATH > manually and using CPYENVVAR(*YES) when doing the > SBMJOB, plus I've tried setting the CLASSPATH inline (as I've > left the > code here) and it makes no difference > > 0133.00 // Close the input stream (no longer needed) > 0134.00 fsClose( inFile); > 0135.00 > 0136.00 // Load the workbook > 0137.00 wb = openWorkbook( fs); > 0138.00 > 0139.00 // Retrieve the sheet > 0140.00 sheet1 = getSheetAt( wb: 0); > 0141.00 // Retreive the Sales row > 0142.00 row = getRow( sheet1: 6); > 0143.00 > 0144.00 // Change sales for Q1 + 500 > 0145.00 cell = getCell( row: 1); > 0146.00 wrkDouble = getNumericCellValue( cell) + %Float( 500); > 0147.00 setCellValue_double( cell: wrkDouble); > ..... > 0166.00 > 0167.00 // Output workbook to file > 0168.00 outFile = createFile( filename); > 0169.00 writeWorkbook( wb: outFile); > 0170.00 > 0171.00 // Exit on error > 0172.00 On-Error; > 0173.00 Exsr *PSSR; > 0174.00 Return; > 0175.00 EndMon; > ... > 0179.00 Exsr Cleanup; > 0180.00 Return; > 0181.00 > 0182.00 /End-Free > > > 0186.00 // > *********************************************************** > 0187.00 Begsr *PSSR; > > 0188.00 // > *********************************************************** > 0189.00 If Not Recursive; > > 0190.00 Recursive = *ON; > > 0191.00 Dump; > > 0192.00 Exsr CleanUp; > > 0193.00 EndIf; > > 0194.00 > > 0195.00 Return; > > 0196.00 > > 0197.00 Endsr; > > 0198.00 > > 0199.00 // > *********************************************************** > 0200.00 Begsr Cleanup; > > 0201.00 // > *********************************************************** > 0202.00 > > 0203.00 *INLR = *ON; > > 0204.00 // Free up all Java objects still in use > > 0205.00 If JNIEnv_P <> *NULL; > > 0206.00 CallP(e) endObjGroup( JNIEnv_P); > > 0207.00 EndIf; > > 0208.00 > > 0209.00 Endsr; > > 0210.00 > > 0211.00 /End-Free > > > > Is there some issue with using a FileInputStream in a batch job or > something?? > Are there any behavioural differences between running Java in > batch and > interactively? > Or am I just trying to do something that can't be done?? > I'm afraid I don't have any Java coding experience at all, > just what I've > picked out from the > V5R2 RPG manual and cobling bits together written by others & would > welcome any input at all.. > Perhaps I shouldn't be mucking around with this stuff, but > you can't blame > a guy for trying, eh? > I'm on V5R2 of the O/S and using JDK 1.3 if that helps any ? > > Sorry if this isn't enough info to be going on yet, I just > wanted to get > my > problem "out there" as it's giving me a real headache. > > Many thanks, > > David > > COMPUTACENTER (UK) LTD > > The contents of this e-mail are intended for the named > addressee only. It contains information which may be > confidential and which may also be privileged. > Unless you are the named addressee (or authorised to receive > for the addressee) you may not copy or use it, or disclose it > to anyone else. If you received it in error please notify us > immediately and then destroy it. > > Computacenter information is available from > http://www.computacenter.com > > This footnote also confirms > that this email message has been swept for the presence of > computer viruses. > > ************************************************************** > ************************************************************* > > _______________________________________________ > This is the Java Programming on and around the iSeries / > AS400 (JAVA400-L) mailing list To post a message email: > JAVA400-L@xxxxxxxxxxxx To subscribe, unsubscribe, or change > list options, > visit: http://lists.midrange.com/mailman/listinfo/java400-l > or email: JAVA400-L-request@xxxxxxxxxxxx > Before posting, please take a moment to review the archives > at http://archive.midrange.com/java400-l. >
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.