This topic describes how to debug Java functions by using VSCode and IDEA.

Notice The content described in this article will no longer be maintained later. If your Function service resources are managed by Funcraft, we recommend that you migrate the resources to Serverless Devs.

For more information about how to migrate Function Compute-related resources from Funcraft to Serverless Devs, see Migrate resources from Funcraft to Serverless Devs.

For more information about Serverless Devs, see Overview.

For more information about how to use Serverless Devs to debug functions, see Debug Functions and Remote debug Using s Local Related Commands.

We apologize for any inconvenience caused.

Using VSCode to Debug Java Functions

This topic uses the function name demo and debugging port 3000 as an example.

Notice When you use VSCode to debug Java functions, you need to install two plug-in Language Support for Java(TM) by Red Hat and Debugger for Java. For more information about how to install the VSCode plug-in, see Install the VSCode plug-in.
  1. Run the following command to debug the function:
    fun local invoke -d 3000 --config VSCode demo
    Expected output:
    using template: .fun\build\artifacts\template.yml
    skip pulling image aliyunfc/runtime-java8:1.9.6...
    you can paste these config to .vscode/launch.json, and then attach to your running function
    ///////////////// config begin /////////////////
    {
        "version": "0.2.0",
        "configurations": [
            {
                "name": "fc/demo/demo",
                "type": "java",
                "request": "attach",
                "hostName": "localhost",
                "port": 3000
            }
        ]
    }
    ///////////////// config end /////////////////
  2. Configure VSCode. After performing the previous step, you need to configure VSCode. Otherwise, function debugging will stop and you cannot continue to implement debugging. For more information, see Configure VSCode.
  3. Use VSCode to debug Java functions.
    1. Click the VSCode editor sidebar to set the breakpoint as follows:inmege8fcvscode
    2. Then, click the IMagevscode2 icon to start debugging.

Debugging Java Functions Using IDEA

  1. Configure IDEA.
    1. In the top navigation bar, choose Run > Edit Configurations…. image10idaefc
    2. In the Run/Debug Configurations dialog box, click the plus icon in the upper-left corner, and then click remote.
  2. On the Configuration tab, set relevant information, and then choose Apply > OK.
    Set the following parameters:
    • Name: Custom is supported.
    • Port: Set this parameter to 3000.

    The operation video for configuring IDEA is as follows:

  3. Click the IDEA editor sidebar to set the breakpoint as follows:imageiedaimagrtc
  4. Run the following command to debug the Java function in the destination directory.
    fun local invoke -d 3000 java8
    Expected output:
    skip pulling images ...
  5. After performing the previous step, function debugging will stop in the expected output of the previous step. You need to select the following mode to connect to IDEA and then start debugging.
    • In the top navigation bar, select Run > Debug....
    • In the upper-right corner, click the debughanshu icon.

Video tutorial

  • Operations video for debugging Java functions using VSCode.
  • Operation video of using IDEA to remotely debug Java functions.