12 Using the Java Card Eclipse Plug-in
This chapter contains the following topics:
Topics:
- Creating a Java Card Project Using the New Java Card Project Wizard
- Creating a Java Card Applet
- Creating a CAP File in a Java Card Project
- Adding a Java Card Package to a CAP File
- Adding a Java Card Applet to a Java Card Package
- Adding a Java Card Static Resource to a CAP File
- Managing Applets and Sending APDU Commands
- Debugging a Java Card Applet in Eclipse Plug-in
Creating a Java Card Project Using the New Java Card Project Wizard
To create a new Java Card Project based on a default template, use the New Java Card Project wizard:
-
Click the File menu, and then select New and Other….
-
In the Other… dialog, under Oracle Java Card SDK, select Java Card Project.
- In the first page of the wizard, configure the following Java Card specific sections:
- Runtime Environment - Select the Java Card Development Kit Simulator that you want to use in the project. The Simulator is selected from the existing configuration. If you have not configured the Simulator, you can use a link that opens the Simulator settings page.
- Java Card Tools - Configure the Java Card Tools bundle path, if not configured already. In Java Card API library, select the API jar to add to the project classpath. The matching
api_classic_annotationsjar is added automatically to the classpath and annotation processor path. Only matching jar pairs in the tools bundle’slibdirectory are listed; changing the tools path refreshes the list. - Application - Configure a Java Card package and/or applet with names and AIDs. When an applet is configured, a default Applet source template is created.
The Java Card API library field offers the following variants, depending on the configured tools bundle:
- Versioned API, such as
api_classic-3.2.0.jar: Standard API for that Java Card version, paired withapi_classic_annotations-3.2.0.jar. - Preview final (
api_classic-preview-final.jar): Only finalized preview features that will become permanent in the next specification, paired withapi_classic_annotations-preview-final.jar. - Preview all (
api_classic-preview.jar): Both evolving and finalized preview features, paired withapi_classic_annotations-preview.jar. This is the default selection when available.
Configure the CAP file converter settings separately to match the selected API. For compact CAP files, use
-enable-preview finalfor finalized preview features or-enable-preview allfor all preview features; omittingallhas the same effect. Preview requires a target platform that implements preview features and supports only the latest Java Card target version. The converter rejects any other-targetversion when preview is enabled. See Managing CAP File Configurations. -
Click Finish.
A new Java Card project is created in the workspace containing the default CAP file configuration.
Changing the Runtime Environment for the Java Card Project
To change the runtime environment:
- Right-click on the Java Card project and select Java Card and Runtime Setting.
- Select a Java Card Development Kit Simulator from the Simulator section. If a Simulator is not configured, click the link that opens the Java Card Simulators global settings pages.
Creating a Java Card Applet
To create Java Card Applets, use the default source template of the Eclipse Plug-in:
-
Select a Java Card Project, click the File menu, and select New and Other….
-
In the Other… dialog, expand Oracle Java Card SDK and select Java Card Applet.
-
In the Package section, click Browse and select the Java package where you want to add the Applet source template.
-
In the Applet name field, enter a Java class compliant name.
-
Click Finish.
The Java Card applet is added to the package.
Creating a CAP File in a Java Card Project
To create deliverables in a Java Card project, you must create and configure CAP files following these steps:
-
Select a Java Card Project, click the File menu, and select New and Other….
-
In the Other… dialog, expand Oracle Java Card SDK and select the Java Card CAP File.
- In the Select CAP file type page, select either Compact CAP file or Extended CAP file. (See Java Card Virtual Machine Specification - Chapter 4.1.2 CAP File Format):
- A compact CAP file contains a single Java Card package
- An extended CAP file contains one or more Java Card packages
- In the Select CAP file settings page, configure the
convertertool options for the build:-
In the CAP File AID section, enter a unique CAP file name and CAP file AID. If the CAP file is a compact CAP file, then the AID field is disabled because the CAP file AID is inherited from the Java Card package that is configured.
-
In the Converter section, configure the
convertertool:- In the Options section, enter values for the CAP file version, target platform, and all the flags. If a CAP file is a compact CAP file, then the version is inherited from the Java Card package that is configured. If a CAP file is an extended CAP file, then the target platform must be 3.1.0 or greater and the mask flag option is disabled.
- In the Export Path section, add the directories in which the
convertertool searches for the export files. Theverifiertool uses the paths added in this step during the build process. If the paths are added from the project, relative paths are generated. - In the CAP Signing section, configure the CAP sign feature of the
convertertool.
Note:
Passwords are stored in plain text within your workspace metadata and can be read by anyone with direct access to this computer.
-
-
Click Finish.
A dialog appears prompting you to confirm if the Java Card package needs to be configured for the CAP file you just created. If you click Yes, the Package Configuration dialog appears. If you click No, the wizard closes and a new configuration file to be included in the build is created.
Managing CAP File Configurations
To manage the CAP file configurations list and to edit a CAP file’s configuration, use the CAP file project settings:
- Right-click on the Java Card project and select the Java Card and CAP Files Settings.
- In the Java Card CAP Files page, to manage the CAP files used in the build, use the following options:
- Click Add to create a new CAP file using the wizard.
- Click Edit to edit a CAP file’s configuration using the wizard with all fields set to the previous values.
- Click Delete to delete a CAP file’s configuration from the build.
Adding a Java Card Package to a CAP File
To include a CAP file in the build, it must be in the configured state. A configured CAP file is a CAP file that has at least one Java Card package added to it.
To add a Java Card package to a CAP file:
-
Right-click on the Java Card project and select Java Card and CAP Files Settings.
-
In the Java Card CAP Files page, select a CAP file from the list.
-
Click Add new package.
Note:
If the CAP file is a compact CAP file and it is already configured, then Add new package is disabled. A compact CAP file can contain a maximum of one package only.
- In the Configure Java Card package dialog, configure the following
convertertool specific parameters:- Next to the Package Name field, click Browse… and select a Java package from the project.
- Enter values for the Java Card package AID and version fields.
- Verify the
convertertool flags. The Private flag is available only if the CAP files are extended CAP files.
-
Click OK.
A dialog appears prompting you to confirm if a Java Card Applet needs to be configured for the package that you just created. If you click Yes, the Java Card Applet configuration dialog appears. If you click No, the dialog closes, the CAP file configuration is updated, and the project is rebuilt.
Managing the Java Card Package
To manage the Java Card package added to a CAP file and to edit the Java Card package, use the CAP file project settings:
-
Right-click on the Java Card project and select Java Card and CAP Files Setting.
-
In the CAP Files Settings page, click the arrow to the left of the Java Card CAP Files.
-
Select Java Card Packages.
A list with package names appears.
-
Select a CAP file from the combo list.
The list is populated with the Java Card packages configured for the selected CAP file.
-
To manage the Java Card packages configured for the selected CAP file, perform the following tasks:
- Click Add to add a new Java Card package to the selected CAP file. If the CAP file is a configured compact file, this button is disabled.
- Click Edit to edit an already configured Java Card package.
- Click Delete to delete a Java Card package from the selected CAP file.
Adding a Java Card Applet to a Java Card Package
If a CAP file is an applet CAP file, then you need to configure the applets that are contained in it. A Java Card Applet is a class contained in a Java Card package.
To add a Java Card Applet to a Java Card package:
-
Right-click on the Java Card project and select the Java Card and CAP Files Settings.
-
In the CAP Files Settings page, click the arrow to the left of the Java Card CAP Files.
-
Select Java Card Packages and the CAP file in which you want to add the Applet.
-
Select the package that contains the Applet you want to add.
-
Click Add new applet.
- In the Configure Java Card Applet window, set the
convertertool parameters for the applets:- In the Applet section, click Browse… and select the applet class from the list.
- In the Applet AID section, enter a value for the PIX part of the AID of the Java Card Applet. The RID part of the AID is automatically populated based on the Java Card package configuration.
-
Click OK.
The window closes, the CAP file configuration is updated, and the project is rebuilt.
Managing Java Card Applets
To manage Java Card Applets and to edit them, use the CAP file project settings:
-
Right-click on the Java Card project and select the Java Card and CAP Files Settings.
-
In the CAP Files Settings page, click the arrow to the left of the Java Card CAP Files.
-
Click the arrow to the left of the Java Card Packages.
-
Select Java Card Applets.
A list with Applets appears.
-
Select a CAP file and Java Card package combination from the combo list.
The list is populated with the Java Card Applets configured for the selected combination.
-
To manage the Java Card Applets configured for the selected combination, perform the following tasks:
- Click Add to include a new Java Card Applet to the selected CAP file or package combination.
- Click Edit to modify an already configured Java Card Applet.
- Click Delete to remove a Java Card Applet from the selected CAP file or package combination.
Adding a Java Card Static Resource to a CAP File
With Java Card, Version 3.1.0 and later, you can add static resources to a CAP file while loading.
To add a Java Card static resource to a CAP file:
-
Right-click on the Java Card project and select Java Card and CAP Files Settings.
-
In the Java Card CAP Files page, select a CAP file from the list.
-
Click Add new static resource.
- In the Configure Java Card static resource dialog, configure the
convertertool static resource-specific parameters:- In the Static Resource ID field, enter a unique integer number.
- In the Static Resource file path section, click Browse… and select the file that you want to add as a static resource to a CAP file. If the path is inside the project, a relative path is generated.
-
Click OK.
The Configure Java Card static resource dialog closes, the CAP file configuration is updated, and the project is rebuilt.
Managing Java Card Static Resources
To manage Java Card static resources list added to a CAP file, and to edit the Java Card static resource, use the CAP file project settings:
-
Right-click on the Java Card project and select Java Card and CAP Files Setting.
-
In the CAP Files Settings page, click the arrow to the left of the Java Card CAP Files.
-
Select Java Card Static Resources.
A list with static resources appears.
-
Select a CAP file from the combo list.
The list is populated with Java Card static resources configured for the selected CAP file.
-
To manage the Java Card static resources configured for the selected CAP file, perform the following tasks:
- Click Add to include a new Java Card static resource to the selected CAP file.
- Click Edit to modify an already configured Java Card static resource.
- Click Delete to remove a Java Card static resource from the selected CAP file.
Managing Applets and Sending APDU Commands
Use the JCShell Terminal to manage Java Card applets and send APDUs to the Simulator.
-
Start the Simulator by right-clicking on
Java_Card_Simulator_1in Java Card View and selecting Start. -
Open the JCShell Terminal. If the Launch jshell terminal on simulator start check box is selected in the Simulator settings, the terminal opens automatically. Otherwise, right-click
Java_Card_Simulator_1in Java Card View and select Start JShell.
For information about the client methods and sample scripts, see Using JShell as a Simulator Client and Running Sample JShell Scripts.
Debugging a Java Card Applet in Eclipse Plug-in
Use the Java Card Project Debug configuration to start a debugging session for a Java Card project. The configuration starts the Simulator and debug proxy, then connects the Eclipse debugger.
To debug an application:
-
Create (or import) your Java Card project. Make sure that debugging information is generated when the project is built.
Note:
The debugging information is generated only if you select the Enable generation of debugging information check box in the CAP file settings.
-
Right-click the project in Package Explorer and select Debug As > Debug Configurations….
-
In the Debug Configurations dialog, create or select a Java Card Project Debug configuration for the project.
-
In the Java Card tab, review the Simulator, debug proxy, and CAP-file settings. To run JShell scripts when the session starts, select Run JShell scripts after simulator and debug-proxy start. Click Add script file… and select the required
.jshfiles. -
Click Debug. Eclipse starts the configured components and opens the Debug perspective. Set breakpoints in the applet source and use the Debug view to step through execution.
Debug Configuration
The Java Card tab of a Java Card Project Debug configuration provides these options:
- Start simulator in debug mode with debug configuration launch starts the local Simulator and stops it when the debug session ends.
- Start debug proxy with debug configuration launch starts the debug proxy and stops it when the session ends.
- Run JShell scripts after simulator and debug-proxy start opens the JCShell Terminal and runs the selected
.jshfiles after the Eclipse debugger connects to the debug proxy. Use Add script file… to select the files and Move up or Move down to specify their execution order. The Java Card startup scripts are loaded before the selected files. Ensure that each selected script connects to the Simulator host and port configured for the debug session. The supplied sample scripts use localhost and port 9025. - CAP paths for debug proxy lists the CAP files used by the debug proxy. CAP files generated by the current project are added automatically.
Under the Connect tab, set Connection Properties > Port to the same value as Proxy to IDE port in the Simulator settings. The default value is 8000.
Note:
The option to start the Simulator is available only when the Simulator configured for the project uses localhost. For a remote Simulator, start it separately in debug mode.
Debugging HelloWorld Sample from Eclipse
These steps explain how to debug the HelloWorld sample. The Java Card Plug-in must be installed and Java_Card_Simulator_1 must be configured.
-
Click the File menu, select Import >General > Projects from Folder or Archive, and select the
appletdirectory from theHelloWorldproject to import theHelloWorldJava Card project into your workspace. If the build doesn’t start automatically, start it manually. - Make sure debugging information generation is enabled for the
HelloWorldpackage:- Right-click on the imported project and select Java Card and CAP Files Settings.
- Select the
HelloWorldCAP file and click Edit. - In the new wizard, click Next on the first page.
- In the second page, select the Enable generation of debugging information check box.
- Click Finish and Apply, and close the wizard.
-
In the Package Explorer, open
HelloWorld.java. Set breakpoints in theinstall()method and at the beginning of theprocess()method. -
Right-click the
HelloWorldproject and select Debug As > Debug Configurations… to configure the debug session before starting it. In the Debug Configurations dialog, create a new Java Card Project Debug configuration or select an existing configuration forHelloWorld. In the Java Card tab, select Start simulator in debug mode with debug configuration launch and Start debug proxy with debug configuration launch.Selecting Debug As > Java Card Project Debug launches the debug session immediately, using a new configuration with default settings or the latest saved configuration for the project. To review or change the settings before launching, use Debug Configurations….
-
To run the supplied HelloWorld script when debugging begins, select Run JShell scripts after simulator and debug-proxy start. Click Add script file… and select
samples/HelloWorld/run-sample-helloworld.jshunderJC_HOME_SIMULATOR. Verify that the CAP file path in the script matches the build output. Alternatively, leave the check box cleared and run the script from the JCShell Terminal after the debug session starts. For script prerequisites and execution instructions, see Running Sample JShell Scripts. -
Click Debug. When an operation initiated by the client causes applet execution to reach a breakpoint, use the Debug view to step through the applet code or resume execution.
If a script is selected in the debug configuration, the JCShell Terminal might not be visible in the Debug perspective. To view the script output or interact with JShell, switch to the Java perspective or open the Terminal view manually in the Debug perspective.