Welcome Serena Central users! CLICK HERE
The migration of the Serena Central community is currently underway. Be sure to read THIS MESSAGE to get your new login set up to access your account.
elopez Absent Member.
Absent Member.
3152 views

Issue with Calling "C$JAVA"

I am having troubles trying to implement a call to a Java program using "C$JAVA".  Here is my Java code:

public class TestClass {

// Main
public static void main(String arg1) {
System.out.println("test");
System.out.println( "TestClass: main command line argument 1: " + arg1 );
}

public void testMethod(String arg1)
{
System.out.println("test");
System.out.println( "testClass: testMethod argument 1: " + arg1 );
}

}

When I try calling the main I get a return of -1 (Invalid Arg):

CALL "C$JAVA" USING CJAVA-CALLJAVAMAIN, "TestClass", "String1" GIVING STATUS-VAL.

When I try calling the testMethod I get a return of -3 (Class not found):

CALL "C$JAVA" USING CJAVA-CALLSTATIC, "TestClass", "testMethod", "(X)V", "String1" GIVING STATUS-VAL.

Can anyone help me out with this?  I've also tried taking out the argument to Main but still get the -1 error.

Thanks!

Tags (1)
0 Likes
9 Replies
Micro Focus Expert
Micro Focus Expert

RE: Issue with Calling "C$JAVA"

Do you have JAVA_LIBRARY_NAME=jvm.dll set up as an environment variable on windows. A fully qualified path can be added with the name. Also, add the location of jvm.dll/libjvm.so to the PATH environment variable. On windows, the entry will look like: PATH=<additional path info>;C:\Program Files\Java\jdk1.5.0_03\jre\bin\client;

For convenience, it may be helpful to have the Java bin directory in the PATH as well. On windows, that

directory might be C:\Program Files\Java\jdk1.5.0_03\bin.

0 Likes
elopez Absent Member.
Absent Member.

RE: Issue with Calling "C$JAVA"

I have the PATH set up correctly.  I also had JAVA_LIBRARY_NAME in my config file and not as an environment variable but putting it there didn't make any difference either.

0 Likes
Chuck Edgin Absent Member.
Absent Member.

RE: Issue with Calling "C$JAVA"

You should add a line like this in your config file:

JAVA_OPTIONS    -Djava.class.path=/path/to/directory

The value beyond the = can be a colon-separated (Unix) or semicolon-separated (Windows) list of locations to search for classes.  Each element in the list should be either a directory or the name of a .jar file.

0 Likes
elopez Absent Member.
Absent Member.

RE: Issue with Calling "C$JAVA"

In the JavaInteropInstructions.txt file it says "For Java calling COBOL, JAVA_OPTIONS should specify ...".  I'm trying COBOL to Java.

I did put this into the config and gave it a shot but still have the same results.

0 Likes
Micro Focus Expert
Micro Focus Expert

RE: Issue with Calling "C$JAVA"

Are your Java objects (class files) in the runtime bin directory or somewhere else?

0 Likes
elopez Absent Member.
Absent Member.

RE: Issue with Calling "C$JAVA"

They were in another directory.  I tried moving them to the runtime bin directory but still have the same results.

0 Likes
Micro Focus Expert
Micro Focus Expert

RE: Issue with Calling "C$JAVA"

Are you able to get the sample programs to run? C:\Program Files (x86)\Micro Focus\Acucbl921\AcuGT\sample\java

I notice you call javamain, but wonder if you should be calling Java-new CALL "C$JAVA" USING CJAVA-NEW, "name-of-your-java-object", "()V" GIVING OBJECT-HANDLE.

0 Likes
Chuck Edgin Absent Member.
Absent Member.

RE: Issue with Calling "C$JAVA"

You are correct that it's needed for Java calling COBOL, so Java can find the CVM.jar file.  But it's also needed for COBOL calling Java, so that your Java classes can be located. If this isn't set correctly, you get the "class not found" error. Not sure what's causing the Invalid Arg error.

What platform and ACUCOBOL version are you testing this with?

0 Likes
elopez Absent Member.
Absent Member.

RE: Issue with Calling "C$JAVA"

I was finally able to get the sample program working by changing to use the CJAVA-NEW and CJAVA-CALLNONVIRTUAL calls.  I know I tried that before, but I must have had something off.

However, when I switch this over to the actual Java program I am using, the InvalidArg error returns.  I believe I have this narrowed down to some code that throws a couple exceptions.  I verified it was that part of the code by commenting out those lines, calling it again and getting a Success returned.

Even though they are in private methods and I am catching them within those methods, I'm still getting the -1 returned.  I have added the check for the exception, but that's a value -13.

Is there anything else I need to add to either program?  Thanks!

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.