Java Card Development Quick Start Guide
Contributed by Tim Boudreau, maintained by Ruth Kusterer
Java Card is an interesting platform to work with - a JVM that runs on smart cards and tiny devices that fit in the palm of your hand. As of Java Card 3.0, it comes in two flavors:
To complete this tutorial, you need the following software and resources:
Since a smart card does not have a user interface, you either need a smart card reader to read and write the data on your cards, or use the emulator included in the Java Card Reference Implementation (RI). This tutorial will use the emulator.
Note: the Java Card plugin works on any operating system, but the Java Card Reference Implementation emulator is only available for Windows. However, you can set it up as a Java Platform on other operating systems by pointing NetBeans to an installation of the RI on a Windows partition on a Mac or Linux system, but you won't be able to run projects using this setup.
Installing Plugins into the NetBeans IDE
Registering the Java Card Platform
If you downloaded the Java Card 3.0.2 Runtime Bundle from the Plugin Manager, the Java Card SDK is already set up as a platform for you. However if downloaded and installed the Platform from java.sun.com you can use the Tools > Java Platforms menu to add the Java Card Platform to the IDE the same way as registering any Java platform.
Once you have set up the Java Card platform it is listed in the Services tab in the IDE. If the Services tab isn't visible, choose Windows > Services from the menu.
One "platform" may have multiple "devices". You deploy a project to a specific device on a specific platform.
Choose File > New Project from the menu, and click the Java Card category. There are several kinds of Java Card projects you can create. All of them are built with Apache Ant, just like NetBeans Java SE projects.
Classic Applet projects create a traditional Java Card applet for smaller devices, just like the applets used in Java Card 2.0 and older. Classic library projects are like Classic Applet projects, without the applet — it's some code that you expect to be on the device, that might be shared between applets.
Extended Applet and Library projects use the extended API in Java Card 3.0—so you can use java.lang.String and so forth. The boot classpath will be different for Classic and Extended projects, so, for example, code completion will not show java.lang.String in Classic projects, but will in Extended projects.
Web Application projects are probably the coolest feature of Java Card 3.0. You get a skeleton project with a Servlet implemented, and you have access to the full Servlet API. This is vastly easier to work with than either of the Applet-style application types—you don't need any special code on the client to interact with an application running on a device, just a web browser! You can test your applications locally using the Reference Implementation and your desktop web browser.
For this tutorial we create a new Web Project.
In the new web project Enter "Card Web Application" as project name and set the project location to your NetBeansProjects directory. Click Finish and the project appears in the Project tab.
Right-click the project node in the Project tab and choose Properties from the context menu. In the Run section of the Project Properties window, you can change the platform and device that a project deploys to. Click Close to save your changes.
Working on a Java Card web application is just like working on any other web application that you deploy to a servlet container. Press the Run button in the toolbar to run the Hello World sample. When running a Java Card web app, a web browser window will open, showing the servlet's output: Hello from webapplication1.MyServlet.
When you run applet-type projects, the NetBeans IDE offers two useful interfaces: command-line output, and the Java Card console. Use the console to interact with the applet: You can send data in hexadecimal and read the replies.
Tip: The RI contains further sample projects that are ready to be opened and run in the NetBeans IDE.
Java Card involves two bits of arcana which you don't encounter in other Java platforms:
While these two things are somewhat complicated, the NetBeans plug-ins do their best to abstract away the complexities of dealing with them, as follows:
Currently the tools only support the Java Card 3.0.2 Reference Implementation, but they have an extensible API for integrating vendor cards. The platform and device definitions are simply Properties files which are imported by the build script.
Deployment is done through a set of Ant tasks provided by the card vendor. This means that the projects created can be run outside the IDE, there is no lock-in. The sources for the Ant tasks that are part of the Java Card RI can be downloaded from the Java Card project portal, along with NetBeans-ready sample projects.
Are you a card vendor who has created Java Card deployment tools? Contact plugin author for details on how to integrate your card! Integration can be done at several levels, depending on how much support you wish to provide within the IDE for your card.