Generating CAP Files From Java Card Assembly Files

Use the capgen tool to generate a compact CAP file from a given Java Card Assembly file or an extended CAP file from one or more Java Card Assembly files. The CAP file that is generated has the same contents as a CAP file produced by the Converter. The capgen tool is a backend to the Converter.

Running capgen

To run capgen:

  1. Enter the following on the command line (see Table 6-4 for a description of the options):

capgen.bat [options] filename

Note:

The file to invoke capgen is a batch file (capgen.bat) that must be run from a working directory of JC_HOME_TOOLS\bin in order for the code to execute properly.

Table 6-4 capgen Command Line Options

Option Description

-help

Prints a help message.

-nobanner

Suppresses all banner messages.

filename

Specifies the Java Card Assembly file in case of the compact CAP file generation or a capgen JSON configuration file in case of the extended CAP file generation.

-o filename

Enables you to specify an output file. If the output file is not specified with the -o flag, output defaults to the file a.jar in the current directory.

-version

Outputs the version information.

-config

Enables capgen to run in the extended mode. In this case, the filename parameter is a JSON configuration file, similar to the one given for the Converter in the extended mode. The JCA input files are defined in the configuration file.

Using a JSON Configuration File for capgen in the Extended Mode

In the extended mode, the capgen tool generates extended CAP files, from one or multiple Java Card Assembly files.

For using the capgen tool in the extended mode, a JSON configuration file must be used with the -config option. This JSON file is similar to the one used by the Converter tool (see Using a JSON Configuration File for Converter in the Extended Mode). The only difference is, some of the general conversion parameters that are used by the Converter tool, including the export paths, are not used by the capgen tool. This is because, this information is already present in the JCA files. For each of the package, only the path to the JCA files is provided. The information that is not present in the JCA files remain in the JSON file, similar to the extended CAP file information and static resources information.

The configuration in the JSON file is a JSON object with a single field, inputConfig. All other fields are defined inside this field at different levels of hierarchy. The description of levels follows:

Table 6-5 JSON File Options for capgen

Option Level Description
CAP_AID CAP file The AID of the CAP file available as an executable load module.
CAP_name CAP file The name of the CAP file generated by the Converter. On the disk, the name of the CAP file would look like <CAP_name>.cap and all the components inside the CAP file will be located in the <CAP_name>/javacard directory.
CAP_version CAP file The user-defined version of the CAP file as an executable load module.
debug CAP file Generates the optional debug component of a CAP file. The same rules apply to the compact mode.
outputDir CAP file Sets the root directory for output of the CAP file.
inputPackages CAP file An array of JSON objects, each representing the configuration for the Java package to be converted and added to the CAP file.
staticResources CAP file An array of JSON objects. Each representing the configuration for a static resource to be loaded on the CAP file.
jcainputfile Package

A valid path to an existent and accessible Java Card Assembly file converted for this package.

This path can be given as a relative path. Relative paths conform to the same rules as the Converter JSON configuration files. These are relative to the location of the JSON configuration file.

outputDir Package Sets the root directory for output of the JCA and EXP files generated for this package. The same rules apply for the compact mode. If this option is not set, the baseDir value is taken.
id Static Resource An integer representing the identification number for the static resource. The static resource IDs must be unique across the CAP file.
file Static Resource A valid system path to an existent and accessible file on the disk. The contents of this file is loaded as binary data in the CAP file for the static resource.

Capgen JSON Configuration File Sample

The capgen JSON configuration file sample follows:

{
	"inputConfig": {
		"CAP_AID": "01:02:03:04:05:10",
		"CAP_name": "hellosample",
		"CAP_version": "1.0",
		"debug": true,
		"outputDir": "thecapfile",
		"inputPackages": [{
			"jcainputfile": "package1\\com\\lib\\javacard\\lib.jca"
		}, {
			"jcainputfile": "package2\\com\\mine\\javacard\\mine.jca"
		}, {
			"jcainputfile": "package3\\com\\sample\\javacard\\sample.jca",
		}],
		"staticResources":[{
			"id" : 1,
			"file" : "staticres\\static1.res"
		}, {
			"id" : 2,
			"file" : "staticres\\static2.res"
		}]
	}
}