Debugging a Java Card Applet in Eclipse Plug-in

From Eclipse, you can run the debug proxy to set breakpoints, get or set variable values, and debug a library.

These steps are an overview of how to debug an application from Eclipse.
The Java Card plug-in for Eclipse must already be installed.
  1. 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.
  2. Create a new Java Card Project Debug configuration and select the Java Card tab. Perform the following tasks:
    1. Specify scripts to be executed when the simulator starts. This not only includes the scripts generated in the apdu_scripts directory, but also other custom scripts. The scripts run in an order. The powerup command is sent only once at the beginning and the powerDown command is not sent. It is important to note that the cap-* scripts for libraries must be executed before the cap-* scripts for the applet if the EEPROM of cref is empty at the start of the debug session.
    2. Add cap files for the applet and imported libraries, which include the code that you want to debug. These not only include CAP files generated in the deliverables directory, but also the CAP files that you generated.
  3. Once the debug session starts, cref starts in debug mode, the script(s) are executed, the debug proxy is started, and the Eclipse debugger connects to the debug proxy.
    You can experiment with the debug perspective and look at the debug console for debug proxy output.
  4. Set breakpoints, and execute scripts.

Debugging HelloWorld Sample from Eclipse

These steps show you how to debug the HelloWorld sample. The Java Card plug-in for Eclipse must already be installed.

Start Eclipse. Sample_Platform and Sample_Device must already be created.
  1. Click the File menu, select Import >General > Projects from Folder or Archive, and select the applet directory from the HelloWorld project to import the HelloWorld Java Card project into your workspace. If the build doesn't start automatically, start it manually.
  2. Make sure debugging information generation is enabled for the HelloWorld package:
    1. Right-click on the imported project and select Java Card and CAP Files Settings.
    2. Select the HelloWorld CAP file and click Edit.
    3. In the new wizard, click Next on the first page.
    4. In the second page, select the Enable generation of debugging information check box.
    5. Click Finish and Apply, and close the wizard.
  3. Create a new debug configuration:
    1. Right-click on the HelloWorld project in the Package Explorer and select Debug As and Debug Configurations.
    2. In the Debug Configurations dialog, double-click Java Card Project Debug (in the list). This will a create new debug configuration named HelloWorld.
    3. Select the Java Card tab.
    4. Select the Start simulator in debug mode… and Start debug proxy… check boxes.
    5. Click Add script.... Browse to the HelloWorld project directory and select the applet\apdu_scripts\cap-HelloWorld.script file. This script will install the applet without creating an applet instance.
    6. Click Add cap file.... Browse to the HelloWorld project directory and select the applet\deliverables\HelloWorld\com\oracle\jcclassic\samples\helloworld\javacard\helloworld.cap file.
    7. Click Debug.
    The debug configuration starts. First, cref is started in debug mode, then the script is executed, the debug proxy is started, and finally the Eclipse debugger connects to the debug proxy.
  4. The Confirm Perspective Switch dialog appears, asking if you want to open the Debug perspective. You may choose to open it, depending on your preference.
    The Debug console shows output from the debug proxy.
  5. In the Package Explorer, locate HelloWorld.java and open it. Set two breakpoints: one in the install() method of the applet, the other in the beginning of the process() method.
    There are several ways to set a breakpoint in Eclipse. In the source code editor, position the cursor on the desired line and do one of the following:
    1. Double-click the left most space on the source code line (the line number will be to the right).
    2. Press Ctrl + Shift + B to toggle the breakpoint (the type of breakpoint will be selected automatically depending on the source code).
    3. Select a specific breakpoint to toggle from the Run menu.
  6. Execute the two remaining scripts in order they appear in the Package Explorer: create-*, then select-* (Right-click on the script and select Java Card and Execute Script).

    After each script runs, execution will suspend on the corresponding breakpoint. Step* and resume debugger commands can be used to resume applet code execution.