Reputation: 1024
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);
}
}
Upvotes: 3
Views: 575
Reputation: 94038
You will simply have to put a package declaration in your Java source file (as you always should, do not ignore the default package warning).
For instance:
package com.myname.javacard.test;
would work fine.
Java Card applets are part of a load module, which basically consists of a normal Java package. This package / load module will also be assigned the AID (the hex code in your convertor). This is however impossible if you use the default package, which is used if you have no package declaration.
Furthermore, you must make sure that your class files are found correctly. Make sure they are under folder .\Token
. It might be that you should simply remove \Token
from the class dir (it's a directory, not a .class
file) or to remove the whole -classdir
altogether.
If unsure, specify the full path to the folder within quotes or double quotes.
Upvotes: 3