我用netbeans中的java卡开发工具包2.2.1创建示例项目。 我的代码是这样的,我按照https://crocs.fi.muni.cz/public/research/smartcard/javacardcompilation的教程。
private byte[] echoBytes;
private static final short LENGTH_ECHO_BYTES = 256;
protected TestApplet02()
{
echoBytes = new byte[LENGTH_ECHO_BYTES];
register();
}
public static void install(byte[] bArray, short bOffset, byte bLength)
{
new TestApplet02();
}
public void process(APDU apdu)
{
byte buffer[] = apdu.getBuffer();
short bytesRead = apdu.setIncomingAndReceive();
short echoOffset = (short)0;
while ( bytesRead > 0 ) {
Util.arrayCopyNonAtomic(buffer, ISO7816.OFFSET_CDATA, echoBytes, echoOffset, bytesRead);
echoOffset += bytesRead;
bytesRead = apdu.receiveBytes(ISO7816.OFFSET_CDATA);
}
apdu.setOutgoing();
apdu.setOutgoingLength( (short) (echoOffset + 5) );
// echo header
apdu.sendBytes( (short)0, (short) 5);
// echo data
apdu.sendBytesLong( echoBytes, (short) 0, echoOffset );
}
我的build.xml就在这里。
<target name="-post-init">
<!-- Java Card Ant Tasks definition -->
<path id="jc-tasks" >
<pathelement path="${jctasks.path}"/>
</path>
<taskdef name="convert"
classname="com.sun.javacard.ant.tasks.ConverterTask"
classpathref="jc-tasks" />
<taskdef name="verifycap"
classname="com.sun.javacard.ant.tasks.VerifyCapTask"
classpathref="jc-tasks" />
<!-- Java Card classpath -->
<path id="jc-classpath" >
<pathelement path="${jc.home}/lib/converter.jar"/>
<pathelement path="${jc.home}/lib/offcardverifier.jar"/>
<pathelement path="${jc.home}/lib/scriptgen.jar"/>
<pathelement path="${jc.home}/lib/apdutool.jar"/>
<pathelement path="${jc.home}/lib/apduio.jar"/>
<pathelement path="."/>
</path>
</target>
<!-- Target responsible for conversion and verification of the applet -->
<target name="convert" depends="init">
<convert
dir="${build.classes.dir}"
nobanner="true"
JCA="true"
EXP="true"
CAP="true"
packagename="${jc.package.name}"
packageaid="${jc.package.AID}"
majorminorversion="${jc.package.version}">
<AppletNameAID
appletname="${jc.package.name}.${jc.applet.name}"
aid="${jc.applet.AID}"/>
<exportpath>
<pathelement path="${jc.export_files}"/>
</exportpath>
<classpath refid="jc-classpath"/>
</convert>
<verifycap Verbose="true" CapFile="${build.classes.dir}/${jc.package.path}/javacard/${jc.package.shortName}.cap">
<exportfiles file="${jc.export_files}/java/lang/javacard/lang.exp" />
<exportfiles file="${jc.export_files}/javacard/framework/javacard/framework.exp" />
<exportfiles file="${jc.export_files}/javacard/security/javacard/security.exp" />
<exportfiles file="${jc.export_files}/javacardx/crypto/javacard/crypto.exp" />
<exportfiles file="${build.classes.dir}/${jc.package.path}/javacard/${jc.package.shortName}.exp" />
<classpath refid="jc-classpath"/>
</verifycap>
</target>
<!-- Overriding target, which runs conversion and verification instead of creating JAR file -->
<target name="jar" depends="init,compile,convert">
</target>
<!-- Target, which runs specific script via GPShell -->
<target name="run-script" depends="init">
<!-- Generate and execute build script -->
<copy file="${gpshell.templatepath}\\${gpshell.script}" todir="build//scripts" overwrite="true">
<filterchain>
<expandproperties/>
</filterchain>
</copy>
<exec executable="${gpshell.cmd}">
<arg value="build//scripts//${gpshell.script}"/>
</exec>
</target>
<!-- Overriding target, which runs script during testing -->
<target name="test" depends="jar,run-script">
</target>
我清理并构建我的项目,我收到此错误:&#34; C:\ Users \ BRI \ Documents \ NetBeansProjects \ TestApplet02 \ build.xml:81:taskdef class com.sun.javacard.ant.tasks。无法找到ConverterTask 使用类加载器AntClassLoader []&#34;。我该怎么办?请帮帮我......
答案 0 :(得分:0)
我猜这个教程已经过时了。您可以使用ant-javacard为初学者尝试一种简单的方法,这是一个简单易懂的ant build.xml工具,可以与任何IDE一起使用。