How to generate Java CAP files using the command line

I am trying to create a CAP file for the following program for a smart card compatible with the Java Card 2.2.1 platform:

package helloWorldPackage;

import javacard.framework.APDU;
import javacard.framework.Applet;
import javacard.framework.ISO7816;
import javacard.framework.ISOException;
import javacard.framework.Util;

public class HelloWorldApplet extends Applet 
{
    private static final byte[] helloWorld = {(byte)'H',(byte)'e',(byte)'l',(byte)'l',(byte)'o',(byte)' ',(byte)'W',(byte)'o',(byte)'r',(byte)'l',(byte)'d',};
    private static final byte HW_CLA = (byte)0x80;
    private static final byte HW_INS = (byte)0x00;

    public static void install(byte[] bArray, short bOffset, byte bLength) 
        {
        new HelloWorldApplet().register(bArray, (short) (bOffset + 1), bArray[bOffset]);
        }

    public void process(APDU apdu) 
        {
        if (selectingApplet()) 
            {
            return;
            }

        byte[] buffer = apdu.getBuffer();
        byte CLA = (byte) (buffer[ISO7816.OFFSET_CLA] & 0xFF);
        byte INS = (byte) (buffer[ISO7816.OFFSET_INS] & 0xFF);

        if (CLA != HW_CLA)
            {
            ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
            }

        switch ( INS ) 
            {
            case HW_INS:
                getHelloWorld( apdu );
                break;
            default:
                ISOException.throwIt(ISO7816.SW_INS_NOT_SUPPORTED);
            }
        }

    private void getHelloWorld( APDU apdu)
        {
        byte[] buffer = apdu.getBuffer();
        short length = (short) helloWorld.length;
        Util.arrayCopyNonAtomic(helloWorld, (short)0, buffer, (short)0, (short) length);
        apdu.setOutgoingAndSend((short)0, length);
        }
}

So, I saved it in a file .javawith a name HelloWorldAppletand then compiled it into a file .class, as shown below:

E:\ToCompile\JC_Converter\JCDK\java_card_kit-2_2_1-win-dom\bin>javac -g -source 1.2 -target 1.2 -cp "E:\ToCompile\JC_Converter\JCDK\java_card_kit-2_2_
1-win-dom\lib\api.jar" "E:\ToCompile\HelloWorldApplet.java"
warning: [options] bootstrap class path not set in conjunction with -source 1.2
1 warning

Q1: What is this warning for?

After that, I tried to convert this file .classto its form .cap:

E:\ToCompile\JC_Converter\JCDK\java_card_kit-2_2_1-win-dom\bin>converter -debug -verbose -classdir E:\ToCompile helloWorldPackage 0xa0:0x0:0x0:0x0:0x6
2:0x3:0x1:0xc:0x6:0x1 1.0
error: input class directory E:\ToCompile\helloWorldPackage not found.
Usage:  converter  <options>  package_name  package_aid  major_version.minor_version
OR
converter -config <filename>
                    use file for all options and parameters to converter
Where options include:
        -classdir <the root directory of the class hierarchy>
                      set the root directory where the Converter
                      will look for classes
        -i            support the 32-bit integer type
        -exportpath  <list of directories>
                      list the root directories where the Converter
                      will look for export files
        -exportmap    use the token mapping from the pre-defined export
                      file of the package being converted. The converter
                      will look for the export file in the exportpath
        -applet <AID class_name>
                      set the applet AID and the class that defines the
                      install method for the applet
        -d <the root directory for output>
        -out  [CAP] [EXP] [JCA]
                      tell the Converter to output the CAP file,
                      and/or the JCA file, and/or the export file
        -V, -version  print the Converter version string
        -v, -verbose  enable verbose output
        -help         print out this message
        -nowarn       instruct the Converter to not report warning messages
        -mask         indicate this package is for mask, so restrictions on
                      native methods are relaxed
        -debug        enable generation of debugging information
        -nobanner     suppress all standard output messages
        -noverify     turn off verification. Verification is default

Well, as you can see, I get the error: input directory E: \ ToCompile \ helloWorldPackage was not found ..

Q2: Why is the converter looking for this way? I specified the directory E:\ToCompileas a class directory, but concatenated my specified path with the name of my software package! why?

Q3: .cap Winrar, AID AID header.cap applet.cap. AID, - cap?


: (Thanx to Mr Bodewes Answer)

HelloWorldApplet.java (i.e HelloWorldApplet.class) helloWorldPackage ( Myptt) . convert:

E:\ToCompile\JC_Converter\JCDK\java_card_kit-2_2_1-win-dom\bin>converter -debug -verbose -classdir E:\ToCompile\ helloWorldPackage 0xa0:0x0:0x0:0x0:0x
62:0x3:0x1:0xc:0x6:0x1 1.0

Java Card 2.2.2 Class File Converter, Version 1.3
Copyright 2005 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.

parsing E:\ToCompile\helloWorldPackage\HelloWorldApplet.class
converting helloWorldPackage.HelloWorldApplet
error: export file framework.exp of package javacard.framework not found.

conversion completed with 1 errors and 0 warnings.

- -exportpath :

E:\ToCompile\JC_Converter\JCDK\java_card_kit-2_2_1-win-dom\bin>converter -debug -verbose -exportpath E:\ToCompile\JC_Converter\JCDK\java_card_kit-2_2_
1-win-dom\api_export_files -classdir E:\ToCompile\ helloWorldPackage 0xa0:0x0:0x0:0x0:0x62:0x3:0x1:0xc:0x6:0x1 1.0

Java Card 2.2.2 Class File Converter, Version 1.3
Copyright 2005 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.

parsing E:\ToCompile\helloWorldPackage\HelloWorldApplet.class
converting helloWorldPackage.HelloWorldApplet
parsing E:\ToCompile\JC_Converter\JCDK\java_card_kit-2_2_1-win-dom\api_export_files\javacard\framework\javacard\framework.exp
parsing E:\ToCompile\JC_Converter\JCDK\java_card_kit-2_2_1-win-dom\api_export_files\java\lang\javacard\lang.exp
writing E:\ToCompile\helloWorldPackage\javacard\helloWorldPackage.exp
writing E:\ToCompile\helloWorldPackage\javacard\helloWorldPackage.jca
error:  Static array initialization in class helloWorldPackage/HelloWorldApplet in library package not allowed.

Cap file generation failed.

conversion completed with 1 errors and 0 warnings.

, converter applet, ( -applet <AppletAID> AppletClassName) , ( ), , , AID, AID header.cap (, , applet.cap) cap. ( Q3):

C:\Users\AmirEbrahim\Desktop\JC_Converter\JCDK\java_card_kit-2_2_1-win-dom\bin>converter -debug -verbose -exportpath C:\Users\AmirEbrahim\Desktop\JC_C
onverter\JCDK\java_card_kit-2_2_1-win-dom\bin  -classdir C:\Users\AmirEbrahim\Desktop\JC_Converter\JCDK\java_card_kit-2_2_1-win-dom\bin -applet 0xa0:0
x0:0x0:0x0:0x62:0x3:0x1:0xc:0x6:0x1:0x2 HelloWorldApplet helloWorldPackage 0xa0:0x0:0x0:0x0:0x62:0x3:0x1:0xc:0x6:0x1 1.0

Java Card 2.2.2 Class File Converter, Version 1.3
Copyright 2005 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.

parsing C:\Users\AmirEbrahim\Desktop\JC_Converter\JCDK\java_card_kit-2_2_1-win-dom\bin\helloWorldPackage\HelloWorldApplet.class
converting helloWorldPackage.HelloWorldApplet
parsing C:\Users\AmirEbrahim\Desktop\JC_Converter\JCDK\java_card_kit-2_2_1-win-dom\bin\javacard\framework\javacard\framework.exp
parsing C:\Users\AmirEbrahim\Desktop\JC_Converter\JCDK\java_card_kit-2_2_1-win-dom\bin\java\lang\javacard\lang.exp
writing C:\Users\AmirEbrahim\Desktop\JC_Converter\JCDK\java_card_kit-2_2_1-win-dom\bin\helloWorldPackage\javacard\helloWorldPackage.exp
writing C:\Users\AmirEbrahim\Desktop\JC_Converter\JCDK\java_card_kit-2_2_1-win-dom\bin\helloWorldPackage\javacard\helloWorldPackage.jca

conversion completed with 0 errors and 0 warnings.
+4
1

: [options] bootstrap -source 1.2

?

, 1.2 , .. JRE. , JRE, Java 1.2. , , , Java Card, . , .

Q2: ? E:\ToCompile , ! ?

Java . , , , . , package package1.package2; MyApplet, , package1/package2/MyApplet.java . . Java, Java-.

Q3: .cap Winrar, AID header.cap applet.cap. AID, - cap?

Applet /AID , ( , , ).

+2

Source: https://habr.com/ru/post/1629341/


All Articles