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
, and17
for JavaCard3.1.0
;1.8
and11
for earlier versions;
- Fetch JavaCard SDKs:
git submodule update --init
; - Set required JavaCard SDK version (the options are the sub-folders of
sdk/javacard_sdks
without the trailing_kit
):sdk.version
property insrc/build.xml
;sdk.version
property 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.class
property insrc/build.xml
; - Update the applet class name in
appletClass
incom.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.class
property insrc/build.xml
; - Change the
groupId
property insrc/pom.xml
; - Change the
groupId
property intest/pom.xml
; - Update the applet class name in
appletClass
incom.vadimtch.applet_template.test.SimulatorWrapper
;
- Change the applet AID:
- Change the
package.aid
property insrc/build.xml
- this must be a colon-separated list of 5-16 hex bytes; - Change the
applet.aid
property insrc/build.xml
- this must start with the package AID and also be no longer than 16 bytes; - Update the applet AID in
appletAID
incom.vadimtch.applet_template.test.SimulatorWrapper
;
- Change the
- Rename the applet
.jar
and.cap
files:- Change the
package.filename
property insrc/build.xml
- this is the filename used for the two files when creating them during a build; - Update the
package.filename
property 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_sdks
and note its name; - Set the
sdk.version
property insrc/build.xml
to 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.version
property insrc/pom.xml
.