javaantclasspathjavacard

How to properly include external jar file in javacard ant build?


I have an issue with ant build while including external JAR file. I have a JAR file from another project that I want to import.

<?xml version="1.0" encoding="UTF-8"?>
<project name="TEST-Applet" default="build-cap" basedir=".">

    <get src="https://github.com/martinpaljak/ant-javacard/releases/download/v23.08.29/ant-javacard.jar" dest="."
         skipexisting="true"/>
    <taskdef name="javacard" classname="pro.javacard.ant.JavaCard" classpath="ant-javacard.jar"/>

    <property name="src.dir" value="src"/>
    <property name="build.dir" value="build"/>
    <property name="target.dir" value="target"/>
    <property name="test.dir" value="testing"/>
    <property name="jc.sdk.kit" value="../jc_sdks/jc310r20210706_kit"/>
    <property name="jc.sdk.target" value="3.0.5"/>
    <property name="test_info.jar" value="src/com/info/otherapplet/test_info.jar"/>

    <property name="pkg.ver" value="2.0"/>
    <property name="pkg.aid" value="XX:00:00:00:00"/>
    <property name="applet.version" value="2.0.0"/>
    <property name="applet.aid" value="XX:00:00:00:00"/>
    <property name="applet.artifact" value="test-applet.cap"/>
    <property name="applet.class" value="com.test.testapplet.TestApplet"/>

    <target name="clean" description="Clean up build artifacts (*.class, *.cap)">
        <delete failonerror="false">
            <fileset dir="${build.dir}" includes="**"/>
            <fileset dir="${target.dir}" includes="**/*.cap"/>
        </delete>
    </target>

    <target name="copy-src-to-build">
        <mkdir dir="${build.dir}"/>
        <delete includeEmptyDirs="true">
            <fileset dir="${build.dir}" includes="**"/>
        </delete>
        <copy todir="${build.dir}/src">
            <fileset dir="${src.dir}">
                <include name="**"/>
            </fileset>
        </copy>
    </target>

    <target name="inject-git-version" depends="copy-src-to-build">
        .
        .
    </target>

    <description>Builds the project.</description>
    <target name="build-cap" description="Generate applet artifact (CAP file)" depends="inject-git-version">
        <tstamp/>
        <mkdir dir="${target.dir}"/>
        <javacard jckit="${jc.sdk.kit}">
            <cap targetsdk="${jc.sdk.target}" aid="${pkg.aid}" version="${pkg.ver}"
                 sources="${build.dir}" output="${target.dir}/${applet.artifact}">
                <applet class="${applet.class}" aid="${applet.aid}"/>
                <classpath>
                    <pathelement path="${test_info.jar}"/> <!-- Include the JAR in the classpath -->
                </classpath>
            </cap>
        </javacard>
    </target>
</project>

but with this build.xml I get below error

cap doesn't support the nested "classpath" element.

The folder structure is

project_root    
│
└───src
│   │   com
│   |   │   info
|   |   |   |   otherapplet
│   |   │   |   |   test_info.jar
|   |   |   |   |   TestApplet.java
|   |   |   |   |   Version.java 
│   ant-javacard.jar
|   build.xml
|   README.md

Can anyone please let me now what is the issue with build.xml file and how to resolve it?

Thanks in advance.

P.S: Please let me know if any info is missing. I am new to ant and javacard development


Solution

  • Use the import tag for it

    <javacard jckit="${jc.sdk.kit}">
      <cap targetsdk="${jc.sdk.target}" aid="${pkg.aid}" version="${pkg.ver}"
        sources="${build.dir}" output="${target.dir}/${applet.artifact}">
        <applet class="${applet.class}" aid="${applet.aid}"/>
        <import jar="${test_info.jar}"/>
      </cap>
    </javacard>