Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

Generating Java classes with Ant

Java classes are generated by means of an Ant script. The parameters are given with the file cobol2java.properties as follows:

xml.file=<xml_file>
cobol.struct=<list_of_structure_names>
package.name=<package_name>
doc.dir=<doc_directory>
jar.dest=<jarfile_name>
code.convention={java|cobol}
undef.pic9=<undef_value>

Description of the parameters:

xml.file=<xml_file>

The parameter xml.file specifies the name of the file containing the XML description of the COBOL structure that is to be processed.

Make sure that the DTD newformat.dtd is located in the same directory as the XML file. You can find a copy of newformat.dtd in the directories lib and samples.


cobol.struct=<list_of_structure_names>

In the parameter cobol.struct, specify a space-separated list of COBOL structures. Cobol2Java searches all the elements (records as well as fields) in the input file for the names contained in <list_of_structure_names>. For each found element a Java class is generated. At least one structure name must be specified.

Certain specifications for the parameter cobol.struct are of little use. You should therefore observe the following restrictions:

  • Do not specify two structures that are nested one within the other in a single call. Reason: The class of the lower-level structure is generated twice (as root level and as sub-level class). The class that is generated later overwrites the first and errors occur during the compilation and use of the classes.

  • Do not enter any recurrent structure or field names (occurs, Array). Reason: It is only possible to access the first element of the array via the generated class. Instead, you should specify higher-level structures.

  • The specification of recurrent structure or field names is not permitted. A message is output and no Java classes are generated.

package.name=<package_name>

The parameter package.name contains the name of the package under which the generated Java classes are to be grouped.

doc.dir=<doc_directory>

doc.dir contains the name of the directory for JavaDoc.

jar.dest=<jarfile_name>

jar.dest contains the name of the JAR file that is to be generated.

code.convention={java|cobol}

code.convention specifies the naming convention that is to be used by the Java classes. If cobol is specified then all the names are taken over from the COBOL program wherever possible. Otherwise, all the names are adapted to the Java naming conventions for the naming of classes, variables, methods and objects (see also Naming conventions ).

undef.pic9=<undef-value>

undef.pic9 specifies the specific value in Pic9 fields that is to indicate "undefined". Here, <undef-value> can have the following form:

0x<nn>

where <nn> is the hexadecimal byte value, or

"'<char>'"

where <char> is a printing character with a 1-byte representation.

To obtain the value '<char>' in the Java class, the parameter must also be specified in quotes ("), e.g. undef.pic9="''"

If undef.pic9 is not specified then '0' is the predefined value for undefined Pic9 fields.

Caution! If you specify the byte value with encoding active then you may need to take account of code conversion. See also  Reading a data field .

If you compile generated Java classes, it is important that the class and file names correspond in terms of the use of case-sensitive notation. Since the Windows file system does not make any distinction between uppercase/lowercase, the Java compiler may report the following error when compiling, for example, a class Benid within a file BENID.java:
"[javac] BENID.java:19:class Benid is public, should be declared in a file named Benid.java"

This error occurs if you create the same COBOL structure with code.convention=cobol and then again with code.convention=java. If you want to modify code.convention, you must first delete the sources that were created beforehand in the src directory.

To start the program you call the script runAnt.sh (Unix/Linux system) or runAnt.bat (Windows). This starts generation using the Ant program supplied with Cobol2Java. This generation process results in the Java sources being created in the src directory, compiled, and stored in the JAR file specified in jar.dest. If you do not want to use the Ant supplied, call Ant in the directory containing the build.xml file.

Some of the tools used here require a very large amount of RAM. You should therefore use the options-Xss (stack size) and -Xmx (heap size) to make the adaptations necessary for the large data structures. In Unix/Linux systems, it may also be necessary to adapt the stack size limit using the ulimit command.

If runAnt is to run correctly, it must be possible to call the Java programs javac and javadoc; i.e. the Java SDK program directory must be present in the environment variable PATH.

It is necessary to use the separator "/" or "\\" when specifying the path names for xml.file, doc.dir and jar.dest since Ant interprets "\" and the following character as a control character.

Example 27 Example for a cobol2java.properties file

# Properties to set for Cobol2Java Program
# used by Ant
# Name of Source XML generated by the BS2000 COBOL Compiler
# Make sure the DTD File is available!!
xml.file=cobkb.xml
# Name of the COBOL Records 
# Space separated list: 
# cobol.struct=RECORD1 RECORD3 will create Java classes for 
# RECORD1 and RECORD3
cobol.struct=MPUT-MSG
# Name of the package to be generated
package.name=de.siemens.cob2java.cobkb
#
# Directory for JavaDoc
doc.dir=doc/cobkb
# Jar file name
jar.dest=cobkb.jar

# Determines what code convention the generated code will use
#
# code.convention=java
# code.convention=cobol
code.convention=java
# defines a non numeric value which marks a PIC9 field as undefined
# 
undef.pic9=0x20