Running the Debug Proxy from the Command Line

If you are not using Eclipse for development, you can run the debug proxy and attach another Java technology-enabled debugger to it from the command line.

To run the debugger:

  1. Compile the application's class files using the -g option. If the -g option is not used, it is not possible to set breakpoints in the source code

  2. Generate APDU scripts for applet installation, instance creation and selection by using the script generator tool (scriptgen.bat).

  3. Start cref in debug mode.

    You must set the -debugPort option so that cref opens the specified port to communication with debug proxy. Without this option, the debugging functionality in cref is disabled.

    For example:

    JC_CLASSIC_HOME\bin\cref_tdual.exe -debugPort 9090 [options]
  4. Run the APDU scripts.

    APDU scripts can be executed using apdutool.bat. At a minimum, the installation script must be executed before the debug proxy connects to the VM. Other scripts can be executed later to debug the applet's install() and process() methods

  5. Start jc-debug-proxy as described in Starting the Debugger.

    For example:

      java.exe -jar lib\jc-debug-proxy.jar -capPath C:\workspace\HelloWorld\deliverables\hello\javacard\hello.cap -vmPort 9090   -port 8000

  6. Attach the debugger to the debug proxy.

    NetBeans or any other Java-compatible debugger can be used to connect to the debug proxy using the JDWP protocol. The debugger needs to be configured to connect to the remote Java application running on a specific host and port.

For an example, see:

Debug Proxy Options

To run the debug proxy from the command line, use the following command syntax:

java.exe –jar lib\jc-debug-proxy.jar <debug proxy arguments>

The command line arguments for the debug proxy are:

Command Line Argument Description
-debug-info The source debug-info file that contains debug information for system classes
-gen-debug-info Starts debug proxy in generate debug-info mode  to generate the system classes debug information file using .exp files found on the provided path
-port  The port that the Java debugger connects to
-vmPort  The port that the VM listens on.
-vmHost The hostname of the system the VM is running on
-capPath Required. Path to the cap file(s) being debugged.
-help Short description of help

For example:

java.exe -jar lib\jc-debug-proxy.jar -capPath C:\workspace\HelloWorld\deliverables\hello\javacard\hello.cap -vmPort 9090 -port 8000

Debugging the HelloWorld Sample from the Command Line

To debug the HelloWorld sample from the command line:
  1. Open a Command Prompt window and perform the following:
    1. Navigate to the JC_CLASSIC_HOME\bin directory.
    2. Start the RI by entering the following command at the command prompt:

      cref –o hello.eeprom


      The -o command line option instructs cref to save the EEPROM data to the hello.eeprom file before terminating.

  2. Open a second Command Prompt window and perform the following:
    1. Navigate to the JC_CLASSIC_HOME\samples\classic_applets\HelloWorld\applet directory.
    2. Open the applet.opt file in a text editor and add a new line with -debug option. This option will be passed to the converter to generate debug information.
    3. At the command prompt, invoke ant with a target set to all. The output file is default.out or, optionally, you can specify a different output file with the -D parameter:

      ant -Dredirect.output=outputfile_name all

      This builds the applet, executes the APDU script, and creates an output file in the applet directory.
  3. cref terminates. Restart it in the first window by entering this command:

    cref –debugPort 9090 –i hello.eeprom

  4. In the second command prompt, navigate to the JC_CLASSIC_HOME\lib directory and start the debug proxy:
    java.exe -jar jc-debug-proxy.jar -capPath JC_CLASSIC_HOME\samples\classic_applets\HelloWorld\applet\build\classes\com\sun\jcclassic\samples\helloworld\javacard\helloworld.cap
  5. Start the Java debugger of your choice and attach it to the 8000 port of the localhost.
  6. Now you can set a breakpoint and see it hit after a proper APDU is issued using the apdutool.