I am creating a very simple Java Card Applet (version 2.2.2) but I am new to java cards and I can not figure out how to convert the .class file to the .cap file. I am using the converter.bat file.
I have managed to compile the single .java file to .class with eclipse...
I tried moving my applet to the default package and also removing the package from the top of the code...
I tried googling this problem, without any success...
I tried compiling my code with command line with the -target and -source compatibility options
I followed this tutorial, without any success: https://lavamunky.wordpress.com/2010/03/28/java-card-prog-compile/
when I run:
.\converter.bat -applet 0x01:0x02:0x03:0x04:0x05:0x06:0x07:0x08:0x09:0x00:0x00 Token -classdir .\Token\ -exportpath %JC_HOME%\api_export_files \ 0x01:0x02:0x03:0x04:0x05:0x06:0x07:0x08:0x09:0x00 1.0
it throws me an error message: error: class Token does not belong to package \.
My java applet:
import javacard.framework.*;
public class Token extends Applet {
/* constants declaration */
// code of CLA byte in the command APDU header
final static byte Amblar_CLA =(byte)0xb0;
// codes of INS byte in the command APDU header
final static byte SET_TOKEN = (byte) 0x30;
final static byte GET_TOKEN = (byte) 0x40;
private short token;
/**
* Installs this applet.
*
* @param bArray
* the array containing installation parameters
* @param bOffset
* the starting offset in bArray
* @param bLength
* the length in bytes of the parameter data in bArray
*/
public static void install(byte[] bArray, short bOffset, byte bLength) {
new Token(bArray, bOffset, bLength);
}
/**
* Only this class's install method should create the applet object.
*/
private Token(byte[] bArray, short bOffset, byte bLength) {
token = 0x00;
register();
}
public boolean select() {
return true;
}
public void process(APDU apdu) {
byte[] buffer = apdu.getBuffer();
if ((buffer[ISO7816.OFFSET_CLA] == 0) && (buffer[ISO7816.OFFSET_INS] == (byte)(0xa4)))
return;
if (buffer[ISO7816.OFFSET_CLA] != Amblar_CLA)
ISOException.throwIt(ISO7816.SW_CLA_NOT_SUPPORTED);
switch (buffer[ISO7816.OFFSET_INS]) {
case SET_TOKEN:
setToken(apdu);
break;
case GET_TOKEN:
getToken(apdu);
break;
default: ISOException.throwIt (ISO7816.SW_INS_NOT_SUPPORTED);
}
}
private void setToken(APDU apdu) {
byte[] buffer = apdu.getBuffer();
byte byteRead = (byte)(apdu.setIncomingAndReceive());
if (byteRead != 1)
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
byte newToken = buffer[ISO7816.OFFSET_CDATA];
token = (short)newToken;
}
private void getToken(APDU apdu) {
byte[] buffer = apdu.getBuffer();
short le = apdu.setOutgoing();
if ( le < 2 ) ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
apdu.setOutgoingLength((byte)2);
buffer[0] = (byte)(token >> 8);
buffer[1] = (byte)(token & 0xff);
apdu.sendBytes((short)0, (short)2);
}
}