× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Have you tried specifying CPYENVVAR(*YES) on the SBMJOB command, once you
have the CLASSPATH set in the interactive job?

Steve


----- Original Message -----
From: <David_Hinselwood@xxxxxxxxxxxxxxxxx>
To: <rpg400-l@xxxxxxxxxxxx>
Sent: Thursday, October 23, 2003 9:15 AM
Subject: Calling java methods from RPG in batch


> Help!
>
> Prompted the excellent article by Geert Van Landeghem,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). Has anyone used this with
> some degree of success?
> I've managed to write programs (batch and interactive) that will create
> spreadsheets from scratch
> and write them out to the IFS (which are then emailed out to users), but
> I'm having a problem when
> I try to open up an existing spreadsheet for updating ( I only need to
> change the contents of
> particular cells & re-save the file, plus it means I can use charts &
> other bits and pieces).
>
> I can call my program interactively with no problems at all (having first
> set my CLASSPATH to point to
> where the .jar file is within the IFS) and get an updated spreadsheet at
> the end of it that is persisted to
> the IFS, but if I try to run it 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 a code snippet from the program in question:
>
>
> 0006.00 D jInStream       S               O   CLASS(*JAVA:
> 0007.00 D                                     'java.io.FileInputStream')
>
> 0029.00 D inFile          S                   LIKE( jInStream)
>
>
> 0089.00    // Get pointer to JNI Environment
> 0090.00    JNIEnv_P = getJNIEnv2();
> 0091.00    If JNIEnv_P = *NULL;
> 0092.00       *INLR = *ON;
> 0093.00       Return;
> 0094.00    EndIf;
> 0095.00
> 0096.00    // Create a new local reference frame so we can clear all the
> 0097.00    // java objects in one go
> 0090.00    JNIEnv_P = getJNIEnv2();
> 0091.00    If JNIEnv_P = *NULL;
> 0092.00       *INLR = *ON;
> 0093.00       Return;
> 0094.00    EndIf;
> 0095.00
> 0096.00    // Create a new local reference frame so we can clear all the
> 0097.00    // java objects in one go
> 0098.00
> 0099.00    pushFrame( JNIEnv_P: capacity);
> 0100.00
> 0101.00    // Create a string object to contain the filename
> 0102.00    wrkString = createString( %trim(IFSFile));
> 0103.00    // Trim filename (50A).
> 0104.00    filename = trimString( wrkString);
> 0105.00    // Create FileInputStream.
> 0106.00    inFile = openFile( filename);
>
>                 // a FileInputStream is passed into the poi method so that
> the
>                 // workbook can be opened and loaded
>
> 0107.00    fs = createPOIFSFileSystemForInput( inFile);
> 0108.00    // Load the workbook
> 0109.00    wb = openWorkbook( fs);
>
>
> (It's probably not relevant, but) I'm using the JNI to create/destroy JVM
> and do
> garbage collection thanks to some really useful articles posted by Barbara
> Morris.
>
>
> The error occurs when statement 0107.00 is executed. The batch job doesn't
> seem
> to have any problems coping with calling other Java methods (to create
> String
> objects, numbers etc), and I don't think it's a CLASSPATH problem?. Is
> there
> some issue with using a FileInputStream in a batch job or something??
> Apologies in advance, but as you've probably already deduced, I don't have
> any
> Java experience at all.
>
> I'm on V5R2 of the O/S and using JDK 1.3 if that helps any ?
>
>
> FYI
>
> Here's my FileInputStream contructor prototype
>
> 0017.00  * // FileInputStream CONSTRUCTOR
> 0018.00  * // openHandle = openFile( fileName)
> 0019.00 D openFile        PR              O   EXTPROC(*JAVA:
> 0020.00 D                                     'java.io.FileInputStream':
>
> 0021.00 D                                     *CONSTRUCTOR)
> 0022.00 D fileName                        O   CLASS(*JAVA:
> 0023.00 D                                     'java.lang.String')
> 0024.00
>
>
> And here is my POIFSFileSytem prototype (if it helps)
>
> 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)
> 0029.00 D                                     CLASS( *JAVA:
> 0030.00 D 'org.apache.poi.poifs.filesystem-
> 0031.00 D                                     .POIFSFileSystem')
> 0032.00 D  inputStream                    O   CLASS(*JAVA:
> 0033.00 D                                     'java.io.InputStream')
>
>
>
> 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.
>
> ps Apologies if this isn't the right forum or format for this as I've not
> posted before & I'm stuck with
> using Lotus Notes as my mail agent here at work (don't have a newsgroup
> reader either).
>
>
> Many thanks,
>
> David Hinselwood
>
>
> 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 RPG programming on the AS400 / iSeries (RPG400-L) mailing list
> To post a message email: RPG400-L@xxxxxxxxxxxx
> To subscribe, unsubscribe, or change list options,
> visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
> or email: RPG400-L-request@xxxxxxxxxxxx
> Before posting, please take a moment to review the archives
> at http://archive.midrange.com/rpg400-l.
>
>

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

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.