skip to main content

The Basics : isCOBOL and Java : Class loading

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.
Starting with Java version 6 (also known as 6.0 and 1.6.0) 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:
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 debugger main class is named “com.iscobol.debugger.GraphDebugger”. So if iscobol.jar is in the class path, you can execute the compiler with “java com.iscobol.compiler.Pcc”, and the debugger with “java com.iscobol.debugger.GraphDebugger”.
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.
2.
For example (the following examples have single lines that may be broken up by print formatting),
or
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 by 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.

Copyright (c) 2017 Veryant
Contact us
Please share your comments on this manual or on any
Veryant product documentation with the email button at the top left