I am trying to call non-static Java methods from an executable file since static methods work fine in this environment. I can accomplish this using cobjrun but it seems like the $java$ is not resolved correctly without cobjrun.
I have tried adding all mf*.jar from the VisualCobol/lib directory into my CLASSPATH before execution but always get a load error similar to the following:
Load error : file '$java$JavaCalculator'
error code: 198, pc=0, call=1, seg=0
198 Load failure
Here are the files that show the failure:
natcobol.cbl
$set ooctrl(+p-f)
program-id. natcobol.
class-control.
claJavacalled is class "$java$JavaCalculator".
* The above maps the Java class 'JavaCalculator' to the COBOL class name 'claJavacalled'
working-storage section.
copy "javatypes.cpy".
01 hCla object reference.
01 l1 jlong value 10.
01 l2 jlong value 5.
01 retl jlong.
01 i1 binary-long value 10.
01 i2 binary-long value 5.
01 ret binary-long.
procedure division.
* display "To Static Java , i1 i2: " i1 "/" i2
* call "java.JavaCalculator.print" using by reference i1 i2.
* Create an instance of the Java class
invoke claJavacalled "new" returning hCla.
display "To Java , i1 i2: " i1 "/" i2
* Invoke the "add" method using the object instance
invoke hCla "add" using by reference i1 i2 returning ret.
display "From Java(int) , ret: " ret
invoke hCla "add" using by reference l1 l2 returning retl.
display "From Java(long) , ret: " retl
* Release the object reference
invoke hCla "finalize" returning hCla.
goback.
end program natcobol.
***************************************************************************
JavaCalculator.java
// JavaCalculator.java
public class JavaCalculator {
// Constructor (the COBOL "new" invokes this)
public JavaCalculator() {
System.out.println("JavaCalculator instance created.");
}
// The method that COBOL calls
public long add(long a, long b) {
return a + b;
}
public int add(int a, int b) {
return a + b;
}
public static void print(int a, int b) {
System.out.println("Printing a+b=" + (a+b));
}
// Optional finalize method
public void finalize() {
System.out.println("JavaCalculator instance finalized.");
}
}
***************************************************************************
makefile
CLASSPATH := ./classes:$(CLASSPATH)
export CLASSPATH
all: compile run
compile:
javac -d classes JavaCalculator.java
cob -x natcobol.cbl
run: compile
cobjrun natcobol
runexe: compile
./natcobol
clean:
rm -f classes/*.class *.o *.idy *.int *.class natcobol
***************************************************************************
Output:
make run
javac -d classes JavaCalculator.java
Note: JavaCalculator.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
cob -i natcobol.cbl
cobjrun natcobol
JavaCalculator instance created.
To Java , i1 i2: +0000000010/+0000000005
From Java(int) , ret: +0000000015
From Java(long) , ret: +00000000000000000015
make runexe
javac -d classes JavaCalculator.java
Note: JavaCalculator.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
cob -x natcobol.cbl
./natcobol
Load error : file '$java$JavaCalculator'
error code: 198, pc=0, call=1, seg=0
198 Load failure
make: *** [makefile:18: runexe] Error 255
Any pointers would be helpful since I have not seen anything documented that states cobjrun must be used.
Eric



