Class loading
In order for the JVM to find Java class files, they must be located in a directory contained in the class path, or stored in a JAR file that is listed in the class path. The Java compiler also uses the class path to locate classes referenced by the source file it is compiling.
The class path is most commonly specified in an environment variable named CLASSPATH. Other Java utilities, such as javap, also use the class path.
On Windows, the class path is a semicolon-delimited list of directories and/or JAR files, similar to the format of the PATH variable, except that in addition to directories, you can specify JAR files. The Java class loader treats JAR files just like directories.
Class path entries can contain the basename wildcard character *, which is considered equivalent to specifying a list of all the files in the directory with the extension .jar or .JAR. See below for links to additional information.
For example:
SET CLASSPATH=.;C:\Program Files\Veryant\isCOBOL2019R2\lib\*;
C:\Program Files\Java\jdk1.8.0_202\lib\tools.jar
The file names in bold in this example are explained below.
The JDK tools.jar File
The isCOBOL Compiler calls the Java compiler via its programmatic interface, not by executing a separate javac process. So in order to compile a COBOL program, the class path must contain the tools.jar file (as shown above). This file contains the programmatic interface to the Java compiler which is a Java class named “com.sun.tools.javac.Main”.
The JRE rt.jar File
In order to run a COBOL program, the class path must contain the rt.jar file (as shown above). This file contains the Java runtime classes.
NOTE - The latest versions of the Java runtime automatically add rt.jar to the class path.
The iscobol.jar File
The iscobol.jar file contains Java classes used for compiling, running and debugging a COBOL program. For example, in iscobol.jar the isCOBOL Compiler main class is named “com.iscobol.compiler.Pcc”, and the runtime main class is named “com.iscobol.invoke.Isrun”. So if iscobol.jar is in the class path, you can execute the compiler with “java com.iscobol.compiler.Pcc”, and the runtime with “java com.iscobol.invoke.Isrun”.
The isCOBOL Compiler uses classes that are in the JDK tools.jar and JRE rt.jar files.
The isCOBOL Runtime Framework and isCOBOL Debugger use classes that are in the JRE rt.jar file. They do not require the JDK tools.jar.
To use iscobol.jar:
1. Make sure that iscobol.jar is listed in the class path setting
2. Include the JDK tools.jar and/or JRE rt.jar if necessary in the classpath setting
For example (the following examples have single lines that may be broken up by print formatting),
SET CLASSPATH=.;C:\Program Files\Veryant\isCOBOL2019R2\lib\*;
C:\Program Files\Java\jdk1.8.0_202\lib\tools.jar
java [options] class_name
or
java -cp=".;C:\Program Files\Veryant\isCOBOL2019R2\lib\*;
C:\Program Files\Java\jdk1.8.0_202\lib\tools.jar" [options] class_name
COBOL programs classes
Unlike the libraries that were previously mentioned, COBOL programs’ classes can be loaded either from the class path or from the code prefix. It depends on the configuration property iscobol.code_prefix.
If such property is set, then COBOL programs classes are searched among the paths specified by the property, otherwise they are searched in the class path. However, if the same class is found in both code prefix paths and class path, then the class is loaded from the class path, hence it’s not good practice to add the same path to both class path and code prefix.
Classes loaded from the code prefix can be cancelled and reloaded multiple times during the runtime session. Instead, classes loaded from the class path are loaded once and then kept in memory for the whole runtime session.
Classes loaded from the code prefix are reloaded in these two situations:
Default situation:
o the program was cancelled by the CANCEL statement or because it’s an INITIAL program,
o the program class file changed on disc since the last time the program was called.
Optimized situation:
o the program was unloaded from the JVM by the C$UNLOAD library routine.
The second situation provides better performance because the runtime doesn’t have to access the disc at every CALL in order to find out if the program class file changed.
The reloading of classes affects directly only standard COBOL programs (e.g. the programs that have PROGRAM-ID at the top of their source code) and not COBOL classes (e.g. the programs that have CLASS-ID at the top of their source code). COBOL classes are reloaded only if they are invoked by a standard COBOL program and such program is reloaded.
In application server environments, the reloading of a class affects all the clients.