An easy-to-use JavaCard project template including everything needed to quickly get started with developing a JavaCard applet.
- Applet code template;
- Applet unit tests template;
- Build and test the applet with one command;
- All dependencies downloaded and included automatically;
All paths are given relative to the repository root.
- Install JDK, Ant, and Maven:
- You could use, for example, SDKMAN to manage your JVM-related SDKs;
- Supported JDK versions are
1.8,11, and17for JavaCard3.1.0;1.8and11for earlier versions;
- Fetch JavaCard SDKs:
git submodule update --init; - Set required JavaCard SDK version (the options are the sub-folders of
sdk/javacard_sdkswithout the trailing_kit):sdk.versionproperty insrc/build.xml;sdk.versionproperty insrc/pom.xml;
- Fetch other dependencies:
cd src,ant fetch; - Build the applet:
ant build; - The build outputs are in
src/target:- Applet compiled as a library for testing:
<applet_name>.jar; - Packaged applet for uploading to a card:
<applet_name>.cap;
- Applet compiled as a library for testing:
- Test the applet:
cd test,mvn test; - Upload the packaged applet to your smartcard:
- Recommended tool: GlobalPlatformPro.
- JavaCard SDKs - downloaded automatically as a git submodule;
- Ant-JavaCard - JavaCard build tool - downloaded automatically by Ant;
- JCardSim - JavaCard simulator used for testing - downloaded automatically by Ant;
.
├── sdk/ (external dependencies)
│ ├── javacard_sdks/ (JavaCard SDKs)
│ └── ...
├── src/ (applet module)
│ ├── src/ (source code)
│ ├── target/ (build outputs)
│ │ ├── template-applet.jar (applet as a library for testing)
│ │ ├── template-applet.cap (packaged applet for uploading to a card)
│ │ └── ...
│ ├── build.xml (Ant build script)
│ └── pom.xml (Maven configuration - needed for some IDEs to locate dependencies)
├── test/ (applet tests module)
│ ├── src/ (code)
│ │ ├── test/ (tests)
│ │ └── main/ (helper classes)
│ └── pom.xml (Maven configuration)
└── ...
The two modules the project consists of are tightly interconnected, so changes in one need to be reflected in another for everything to work. This section describes (hopefully) all the steps you need to take to change some parameters.
- Change the applet class name:
- Rename the class (initially
com.vadimtch.applet_template.src.MyApplet) and the file it is in; - Update the
applet.classproperty insrc/build.xml; - Update the applet class name in
appletClassincom.vadimtch.applet_template.test.SimulatorWrapper;
- Rename the class (initially
- Change the Java package name:
- Change the package name in the source files;
- Rename the package directories in:
src/src/main/java;test/src/main/java;test/src/test/java;
- Change the
applet.classproperty insrc/build.xml; - Change the
groupIdproperty insrc/pom.xml; - Change the
groupIdproperty intest/pom.xml; - Update the applet class name in
appletClassincom.vadimtch.applet_template.test.SimulatorWrapper;
- Change the applet AID:
- Change the
package.aidproperty insrc/build.xml- this must be a colon-separated list of 5-16 hex bytes; - Change the
applet.aidproperty insrc/build.xml- this must start with the package AID and also be no longer than 16 bytes; - Update the applet AID in
appletAIDincom.vadimtch.applet_template.test.SimulatorWrapper;
- Change the
- Rename the applet
.jarand.capfiles:- Change the
package.filenameproperty insrc/build.xml- this is the filename used for the two files when creating them during a build; - Update the
package.filenameproperty intest/pom.xml;
- Change the
- Change the JavaCard SDK version used:
- Ensure that the JDK you are using is supported with the required SDK version (see the Set-up section for details)
- Choose the new SDK version from the list in
sdk/javacard_sdksand note its name; - Set the
sdk.versionproperty insrc/build.xmlto the directory name of the chosen SDK version, without the trailing_kit:- For example, to use JavaCard
3.0.5u3, set it tojc305u3;
- For example, to use JavaCard
- Set the
sdk.versionproperty insrc/pom.xml.